# show mouse position as mouse is moved and create a hot spot
import Tkinter as tk
root = tk.Tk()
def showxy(event):
xm = event.x
ym = event.y
str1 = "mouse at x=%d y=%d" % (xm, ym)
root.title(str1)
# switch color to red if mouse enters a set location range
x = 100
y = 100
delta = 10 # range
if abs(xm - x) < delta and abs(ym - y) < delta:
frame.config(bg='red')
else:
frame.config(bg='yellow')
frame = tk.Frame(root, bg= 'yellow', width=300, height=200)
frame.bind("<Motion>", showxy)
frame.pack()
root.mainloop()
我还不知道
pyusb
,但是您可以用Tkinter(Python中最常用的GUI之一)来处理第二个问题。以下是代码示例(找到here):但是,似乎您不能仅使用Tkinter更改光标位置(请参阅本文thread以获得一些解决方法)。但是,如果您试图在文本中设置位置,您可以使用这个SO-thread:Set cursor position in a Text widget中描述的小部件。在
要禁用鼠标,您可以查看一下this post并调整代码以禁用鼠标而不是touchpad(但是文章首先给出了一些有趣的键)。在
相关问题 更多 >
编程相关推荐