Python Forum
[Tkinter] Is there any way to bind keys to a gui window in tkinter?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Is there any way to bind keys to a gui window in tkinter?
#1
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..
Reply
#2
you can set event types, see: http://infohost.nmt.edu/tcc/help/pubs/tk...types.html
then read about binding levels here: http://infohost.nmt.edu/tcc/help/pubs/tk...types.html
and event sequences here: http://infohost.nmt.edu/tcc/help/pubs/tk...ences.html

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter popup no grabbing the selected keys - Event propagation Wehaveall 2 1,309 Aug-10-2024, 01:18 PM
Last Post: Wehaveall
  Tkinter multiple windows in the same window hosierycouch 1 1,223 May-30-2024, 04:28 AM
Last Post: deanhystad
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 2,519 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 2,160 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 14,243 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 3,438 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 4,946 Apr-16-2022, 04:04 PM
Last Post: DBox
  [Tkinter] bind menator01 1 1,892 Apr-15-2022, 08:47 PM
Last Post: menator01
  How to move in entries using the arrow keys by applying the bind and focus? pymn 4 9,295 Apr-06-2022, 04:29 AM
Last Post: pymn
  why my list changes to a string as I move to another window in tkinter? pymn 4 3,642 Feb-17-2022, 07:02 AM
Last Post: pymn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020