2011-02-22 15 views
0

私は、ユーザーがグラフィックスウィンドウ内のポイントをクリックしたときにx座標を表示する方法を理解しようとしています。何か案は?ありがとう!ここで マウスクリック後にx座標を表示するにはどうすればよいですか? - Python

は私のコードです:

win = GraphWin("Uncle Scrooges Money Bin", 640,480) 
win.setCoords(0,0,80,60) 
win.setBackground("white") 

は、マウスクリックのポイントの1

point1 = win.getMouse() #***************************** 

表示座標を座標取得

セット、グラフィックスウィンドウ1

print("Point 1 coordinates: ", point1) 
+3

それはあなたがウィンドウのために使用しているフレームワークを示し、そしてどのような問題があなたのコードであれば、何が起こるかない役立つだろうか? –

+0

彼はこれを使っているようです:http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node1.html – jdi

+0

また、最後の行には何が印刷されますか? – Robin

答えて

0

Tkinterライブラリを使用すると簡単に言うことができます。

import Tkinter 

def mouse(event): 
    print "Point 1 coordinate :",event.x,event.y 
# event parameter will be passed to the function when the mouse is clicked 
# This parameter also contains co-ordinates of where the mouse was clicked 
# which can be accessed by event.x and event.y 

win = Tkinter.Tk() # Main top-level window 

win.title("Uncle Scrooges Money Bin") 
win.geometry("640x480+80+60") # Set window diensions 

frame = Tkinter.Frame(win, background='white', width=640, height=480) 
# New frame to handle mouse-clicks 

frame.pack() # pack frame(or make frame visible) 
frame.bind('<Button-1>', mouse) 
# Bind mouse-click event denoted by '<Button-1>' to mouse function 

win.mainloop() # Start window main loop 
関連する問題