user2589273
user2589273

Reputation: 2467

Are there any ways to bind the enter key to a Tkinter.Toplevel() window in Python?

I have a tk window opening another. This secondary window is used as my input for a program. I would like to read the results each time the cartage return key is pressed. I read somewhere that the method I am trying to use (below) only works for root .Tk() windows.

input_window.bind('<Return>',lambda: function_to_save_data (args) ) 

Is there a way to get around this, or an alternative way to do such a thing? (I have tried this, and it fails to work, and does not bug out, thus the question above)

Upvotes: 1

Views: 1528

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386342

Bind works for any window, there are no special cases.

The problem you are experiencing is likely due to the fact that top level windows may not get keyboard focus. When you press a key, it is the window with focus that processes the event.

Upvotes: 2

Related Questions