我试着做一个实时显示鼠标坐标的应用程序。我知道pyautogui有displayMousePosition(),但不知何故它不起作用。(我用的是Pycharm)
from tkinter import *
from pyautogui import *
from time import * #I thought the sleep() command would help but didn't work :/
app = Tk()
ms_coor = str(position()) #I storaged the mouse position in a variable.
def update():
while True:
global ms_coor
label1.config(text=ms_coor) #I wanted to update the label without creating a new label in next line.
button1 = Button(app, text="Start", command=update) #Starter button.
button1.grid(row=0, column=0)
label1 = Label(app, text="Please Start")
label1.grid(row=1, column=0)
app.mainloop()
1条答案
按热度按时间qxgroojn1#
加上
pyautogui.position()
。代码片段: