2010-12-23 6 views
1

사용자 그래픽 인터페이스를 작성하기 위해 graphics.py를 사용하려고합니다. 문제는 어떻게하면 마우스 오른쪽 버튼 클릭 이벤트를 캡처 할 수 있습니까? getMouse() 함수는 마우스를 Point 객체로 왼쪽 클릭 한 위치를 반환 할 수 있습니다.getMouse()를 사용하여 마우스 오른쪽 버튼 이벤트를 캡처하는 방법

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

은 내가, 감사 창에서 마우스 오른쪽 버튼으로 클릭 이벤트를 캡처 할 수있는 방법을 알고 싶어요.

+0

당신은 graphics.py 할 수있는 소스를 보라 : Tkinter를 사용

, 여기에 오른쪽 클릭을 감지 한 예이다. 마우스 오른쪽 버튼 클릭에 대한 핸들러를 추가하는 것은 매우 간단합니다. graphics.py는 단순히 Tkinter 프로그램입니다. – Mark

답변

0

숙제? "숙제"태그를 추가하십시오. 나는 당신이 파이썬 GUI를 TkInter 시도하는 것이 좋습니다 것입니다.

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

고마워, 이건 내 숙제가 아니야 호기심에서 나온거야. – Leyond

+0

이것이 숙제라고 생각하는 이유는 무엇입니까? – Vreality

관련 문제