Python Forum
[Tkinter] Is there any way to bind keys to a gui window in tkinter? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Is there any way to bind keys to a gui window in tkinter? (/thread-11083.html)



Is there any way to bind keys to a gui window in tkinter? - Nwb - Jun-21-2018

Just like how you can bind keys to the widget, is it possible to bind certain key clicks that are performed when a certain window is open to a certain action?

Suppose, you want to focus between your widgets using arrow keys.

Googling didn't help but was wondering if you guys have any lead. Is this possible with tkinter at all? What are the alternatives?

If it's not possible, what are plausible alternatives? Presumably having a loop that constantly checks for whether a key is pressed and whether a window is active would be very resource tedious.


Also, forgetting the GUI aspect, how would you efficiently define hotkeys in Python? I assume there's a better way than a loop that checks the button's state every fraction of a second..


RE: Is there any way to bind keys to a gui window in tkinter? - Larz60+ - Jun-21-2018

you can set event types, see: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-types.html
then read about binding levels here: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-types.html
and event sequences here: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-sequences.html

for hot keys, can't vouch for this, but: https://github.com/schurpf/pyhk