April 2018
Beginner
340 pages
7h 54m
English
When generating a custom event, we first need to name it in a way Tkinter will recognize. We can name an event anything we want (assuming it is not already reserved), as long as we enclose it between two less-than and greater-than signs, for example <<custom_event>>.
We can emit this event whenever we like by using the event_generate method of a Tkinter widget. The first argument to this widget will be our custom name, and the remaining keyword arguments will define some properties which will be sent to the handler via the usual event object.
To receive and handle this event, the bind method is used just like before.
Let's have a go at an example program which uses custom events:
import randomimport tkinter as tkwin = tk.Tk() ...