窗口中的文本与开始时保持不变。
from pynput.mouse import Controller
from tkinter import *
root = Tk()
mouse = Controller()
Label(root, text=mouse.position).pack()
root.mainloop()
答案 0 :(得分:2)
您需要使用Listener来进行注视:
from pynput.mouse import Controller
from pynput.mouse import Listener
from tkinter import *
from time import sleep
root = Tk()
mouse = Controller()
var = StringVar()
var.set(str(mouse.position))
def on_move(x, y):
var.set(str((x,y)))
ll = Label(root, textvariable = var)
ll.pack()
with Listener(on_move=on_move) as listener:
root.mainloop()
这对我有用。