python - How do I get mouse position relative to the parent widget in tkinter? -


I need to get the position of the mouse related to the tanker window. Normally speaking, you do not have to "get" this information because it is given to you as part.

"post-text" itemprop = "text">

The event object that has been passed. You probably only need this information in response to an event, and the event gives you this information

Put more information, just to get the information, you just have to get it from Event Object.

Here's an example:

Import Tinkiner Class app: def __init __ (auto, root): f = Tkinter.Frame (width = 100, height = 100 , "Background" = "biscuits") fax (padx = 100, pd = 100) f.bind ("<"> self.OnMouseDown) def OnMouseDown (auto, event): print "frame coordinates:% s /% S "% (Event.x, event.y) Print" root coordinate:% s /% s "% (event.x_root, event.y_root) root = Tkinter.Tk () app = app (root) root. Mainloop ()

Comments