Skip to content Skip to sidebar Skip to footer

How Do I Get The X Coords To Show Up After Mouse Click? - Python

I'm trying to figure out how to get the x coords to show up when the user clicks a point in the graphics window. Any ideas? Thanks! Here's my code: Set graphics window win = Graph

Solution 1:

It would be easier to do what you say using Tkinter library.

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

Post a Comment for "How Do I Get The X Coords To Show Up After Mouse Click? - Python"