1

I was trying to learn a bit more about Tkinter and came across this code online

import Tkiner
import ttk
root = Tk()
l =ttk.Label(root, text="Starting...")
l.grid()
l.bind('<Enter>', lambda e: l.configure(text='Moved mouse inside'))
l.bind('<Leave>', lambda e: l.configure(text='Moved mouse outside'))
l.bind('<1>', lambda e: l.configure(text='Clicked left mouse button'))
l.bind('<Double-1>', lambda e: l.configure(text='Double clicked'))
l.bind('<B3-Motion>', lambda e: l.configure(text='right button drag to %d,%d' % (e.x, e.y)))
root.mainloop()

When I ran this program, and dragged my mouse over the screen while the RMB was pressed it gave me the coordinates as is mentioned it should do in the "B3-Motion" bind.

What exactly does the temp variable "e" refer to in this scenario?

Thanks!

2
  • It's just the first argument to the function − in this case the event that Tkinter sends when you click a button. Commented Mar 25, 2016 at 14:45
  • Under the event attributes Commented Mar 25, 2016 at 14:52

1 Answer 1

2

When you bind a function to an event with widget.bind(...), tkinter will always pass in an argument to the function that represents the event when it calls the function. Typically this is named event, but sometimes abbreviated as e.

The event object has information about the event, such as which widget received the event, the x/y coordinate of the cursor when the event occurred, and other useful information.

You can read a bit more about that object here: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm .

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the help :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.