简体   繁体   中英

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM