Skip to content
Advertisement

Is it possible to view/print to console the idle queue in tkinter?

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.

import tkinter as tk

root = tk.Tk()

# Some widgets
for foo in range(5):
    tk.Button(root, text="Press Me!").pack()

# Bind all widgets to print events
widgets = root.winfo_children()
def event_print(event):
    print(event)

events = [
    "<Button>",
    "<Motion>",
    "<ButtonRelease>",
    "<Double-Button>",
    "<Enter>",
    "<Leave>",
    "<FocusIn>",
    "<FocusOut>",
    "<Return>",
    "<Key>",
    "<Shift-Up>",
    "<Configure>",
]

for widget in widgets:
    for event in events:
        widget.bind(event, event_print)

root.mainloop()

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement