【发布时间】:2014-12-05 10:23:40
【问题描述】:
我想定期检查按钮是否被按下。如果没有,那么我想打印一些东西。我需要简单的例子来实现这一点。提前致谢。
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()
【问题讨论】:
标签: python button tkinter click