我正在尝试使用graphics.py 编写用户图形界面。问题是如何捕获右键事件呢?看来函数 getMouse() 只能返回鼠标左键单击的位置作为 Point 对象。
from graphics import *
def main():
win = GraphWin("My Circle", 100, 100)
c = Circle(Point(50,50), 10)
c.draw(win)
win.getMouse() # pause for click in window
win.close()
main()
我想知道如何捕获窗口中的右键单击事件,谢谢。
我建议你尝试一下TkInter http://wiki.python.org/moin/TkInter对于Python GUI。
这是检测右键单击的示例:
from Tkinter import *
def showPosEvent(event):
print 'Widget=%s X=%s Y=%s' % (event.widget, event.x, event.y)
def onRightClick(event):
print 'Got right mouse button click:',
showPosEvent(event)
tkroot = Tk()
labelfont = ('courier', 20, 'bold')
widget = Label(tkroot, text='Hello bind world')
widget.config(bg='red', font=labelfont)
widget.config(height=5, width=20)
widget.pack(expand=YES, fill=BOTH)
widget.bind('<Button-3>', onRightClick)
widget.focus()
tkroot.title('Click Me')
tkroot.mainloop()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)