Skip to Content
Tkinter GUI Programming by Example
book

Tkinter GUI Programming by Example

by David Love
April 2018
Beginner content levelBeginner
340 pages
7h 54m
English
Packt Publishing
Content preview from Tkinter GUI Programming by Example

Generating events

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() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Tkinter GUI Application Development Blueprints, Second Edition - Second Edition

Tkinter GUI Application Development Blueprints, Second Edition - Second Edition

Bhaskar Chaudhary

Publisher Resources

ISBN: 9781788627481Supplemental Content