我正在试图找出当用户点击图形窗口中的某个点时如何显示x坐标。有任何想法吗?谢谢!
这是我的代码:
设置图形窗口
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)
答案 0 :(得分: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