how to capture the right click event using getMouse()

ぃ、小莉子 提交于 2019-12-11 10:53:40

问题


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.


回答1:


I would recommend you try TkInter for a python GUI.

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()


来源:https://stackoverflow.com/questions/4515929/how-to-capture-the-right-click-event-using-getmouse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!