如何使用getMouse()捕获右键单击事件 [英] how to capture the right click event using getMouse()

查看:253
本文介绍了如何使用getMouse()捕获右键单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用graphics.py编写用户图形界面.问题是如何捕获右键单击事件?看来函数getMouse()可以返回鼠标左键作为Point对象的位置.

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.

推荐答案

我建议您尝试 TkInter 用于python GUI.

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

这篇关于如何使用getMouse()捕获右键单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆