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
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 598 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 894 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 5,033 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 1,966 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,976 Apr-16-2022, 04:04 PM
Last Post: DBox
  [Tkinter] bind menator01 1 1,274 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 4,798 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 2,609 Feb-17-2022, 07:02 AM
Last Post: pymn
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,888 Nov-07-2021, 05:14 PM
Last Post: gw1500se
  [Tkinter] bind lambda keypress counter knoxvilles_joker 15 7,907 Apr-19-2021, 01:56 AM
Last Post: knoxvilles_joker

Forum Jump:

User Panel Messages

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