In reference to In tkinter GUI what are pending events and idle callbacks? question, which asks what are pending events and idle callbacks in tkinter, I was wondering if there is a way to print the event/idle queue to console or a tracelog.
The only potential solution I could come up with is the code below, but I was wondering if there was an easier way.
JavaScript
x
34
34
1
import tkinter as tk
2
3
root = tk.Tk()
4
5
# Some widgets
6
for foo in range(5):
7
tk.Button(root, text="Press Me!").pack()
8
9
# Bind all widgets to print events
10
widgets = root.winfo_children()
11
def event_print(event):
12
print(event)
13
14
events = [
15
"<Button>",
16
"<Motion>",
17
"<ButtonRelease>",
18
"<Double-Button>",
19
"<Enter>",
20
"<Leave>",
21
"<FocusIn>",
22
"<FocusOut>",
23
"<Return>",
24
"<Key>",
25
"<Shift-Up>",
26
"<Configure>",
27
]
28
29
for widget in widgets:
30
for event in events:
31
widget.bind(event, event_print)
32
33
root.mainloop()
34
Advertisement
Answer
I was wondering if there is a way to print the event/idle queue to console or a tracelog.
No, there is not. At least, not without writing your own code in C that hooks into the underlying tcl interpreter.
The solution you propose in your question wouldn’t work 100% either. There are many events that get added to the queue by the tk library itself.