Skip to content
Advertisement

Why doesn’t the .bind() method work with a frame widget in Tkinter?

This code is an attempt to bind a command to a frame, ie. when the “Escape” key is pressed, the window should be destroyed.

JavaScript

if frame1.bind() is replaced by root.bind(), the code works as I would expect it to. Why doesn’t what I’ve written above work?

Advertisement

Answer

The bind works, but the event will only trigger if the frame has focus, and by default a frame does not have the keyboard focus.

Try setting the focus with frame1.focus_set()

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