I am trying to use graphics.py to write a user graphics interface. The problem is that how can I capture the right click event? It seems that the function getMouse() could just returns where the mouse was left-clicked as a Point object.
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()
I want to know how can I capture the right-click event in the window, thanks.
Homework? Please add "homework" tag. I would recommend you try TkInter for a python GUI.
Using TkInter, here is an example that detects a right click:
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()