S
S
Semyon Petrenko2016-01-16 11:06:28
Python
Semyon Petrenko, 2016-01-16 11:06:28

What is event.x, event.x_root and event?

The question arose of how to track the coordinates of the mouse (and other elements). I stumbled upon a piece of code I didn't understand. What are these elements and what do they refer to? I understand that this is passing the coordinates along the axes, but what is this object and parameters? I did not find a separate description. Please chew on your fingers. Thank you!

import Tkinter

class App:
    def __init__(self, root):
        f = Tkinter.Frame(width=100, height=100, background="bisque")
        f.pack(padx=100, pady=100)
        f.bind("<1>", self.OnMouseDown)

    def OnMouseDown(self, event):
        print "frame coordinates: %s/%s" % (event.x, event.y)
        print "root coordinates: %s/%s" % (event.x_root, event.y_root)

root=Tkinter.Tk()
app = App(root)
root.mainloop()

I don't understand this snippet:
def OnMouseDown(self, event):
        print "frame coordinates: %s/%s" % (event.x, event.y)
        print "root coordinates: %s/%s" % (event.x_root, event.y_root)

Found an analog:
def getXY(event):         
    getx=event.x_root       
    gety=event.y_root

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MK, 2016-01-16
@Pogremix

.bind - method for catching events.
Here, a handler is placed for pressing the left mouse button, the event object (event) is passed as a parameter, it contains information about the event, for example, mouse coordinates relative to the window (event.x, event.y) or mouse coordinates relative to the screen (event.x_root, event .y_root)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question