-2
我想定期检查是否按下按钮。如果没有,那么我想打印一些东西。我需要一个简单的例子来实现这个。提前致谢。如何知道右键单击是否在Tkinter python中完成?
from Tkinter import *
import subprocess
def execute_querie1():
counter = 0
global a
a = 0
def onRightClick(event):
print 'Got right mouse button click:',
showPosEvent(event)
print ("Right clickkkk")
close_window()
a = 1
return a
def close_window():
# root.destroy()
tkroot.destroy()
def showPosEvent(event):
print 'Widget=%s X=%s Y=%s' % (event.widget, event.x, event.y)
def quit(event):
print("Double Click, so let's stop")
import sys; sys.exit()
def onLeftClick(event):
a = True
print 'Got light mouse button click:',
showPosEvent(event)
print ("Left clickkkk")
close_window()
return a
subprocess.call(["xdotool", "mousemove", "700", "400"])
tkroot = Tk()
labelfont = ('courier', 20, 'bold')
widget = Label(tkroot, text='Hello bind world')
widget.config(bg='red', font=labelfont)
widget.config(height=640, width=480)
widget.pack(expand=YES, fill=BOTH)
g = widget.bind('<Button-3>', onRightClick)
h = widget.bind('<Button-1>', onLeftClick)
print g
print h
widget.focus()
tkroot.title('Click Me')
tkroot.mainloop()
if __name__ == "__main__":
execute_querie1()
谢谢!我想在一段时间后定期检查点击。我在哪里应该在之前的程序中做出循环? – Pink 2014-12-07 13:52:31
'一段时间后'是什么意思?您可以通过设置第一个'root.after(...)'调用来启动您想要的循环。 – fhdrsdg 2014-12-08 08:57:59