Is it possible to track a mouse pointer full screen in Python?
3 answers
Try the below example code, it will help you understand better
import Tkinter as tk
import Xlib.display as display
def mousepos(screenroot=display.Display().screen().root):
pointer = screenroot.query_pointer()
data = pointer._data
return data["root_x"], data["root_y"]
def update():
strl.set("mouse at {0}".format(mousepos()))
root.after(100, update)
root = tk.Tk()
strl = tk.StringVar()
lab = tk.Label(root,textvariable=strl)
lab.pack()
root.after(100, update)
root.title("Mouseposition")
root.mainloop()
Also please comment if you have any doubts.
+3
source to share
I believe you need to use some system libraries to do this, since Tkinter probably only keeps track of where the pointer is inside the main window.
There is a library for this purpose and a lot more functionality called PyUserInput
Hope this is what you were looking for.
0
source to share