开发者

how to capture the right click event using getMouse()

开发者 https://www.devze.com 2023-02-01 02:26 出处:网络
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 themouse

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)
      开发者_StackOverflow  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.


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

精彩评论

暂无评论...
验证码 换一张
取 消