• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: is there a way to change the keys to navigate the tkinter MenuButton options in python?

Resolved: is there a way to change the keys to navigate the tkinter MenuButton options in python?

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve is there a way to change the keys to navigate the tkinter MenuButton options in python?

Question:

The opening of the menu in the Menubutton widget seems to block any key input aside from the arrow keys, the enter key and the escape key.
I’m trying to assign the function of the enter key in that scenario to another key, but it seems impossible.
I wonder if there’s any way to make that possible and, if not, if any of you can point me to any “homemade” class that could replace the menubutton entirely (except for that flaw).
Thanks in advance for your attention.
[I’ve tried binding the apparent functionality of those keys (arrows, enter and scape) to other keys; I’ve tried to find out where the commands of those keys were rooted for them to be able to work in that scenario; I’ve tried to unbind the functionality of those keys to see if I could find out how they were working; and I tried to make my own similar Menubutton class (with blackjack and hookers). I have miserably failed at all those tasks.]
Here’s a small example of the problem:

Best Answer:

peputito, it’s me, you, from the near future.
I might have found a way around your problem that could help people all around the world in this exact same situation.
First, I want to clarify that I have not yet found why the problem occurs (it still seems to me that, once a menubutton is posted, no key on the keyboard, besides the arrow keys, the return and the escape, is able to work).
BUT, I have come up with a very un-elegant solution that does what you want to achieve:
What I’ve done here is a way to select menubutton options (with whatever keys you want) without having to post the cascade. In my particular case, this works by making a list out of the labels of the radiobuttons in the menubutton, searching for the dictionary that originated them, looking at which option is shown in the menubutton currently, converting that into an index reference, and then invoking the next/prev index that I want selected.
As said, it is not very elegant (if I think that means what I think that means), but it does the trick for the both of us.
Cheers, peputito from the past.
EDIT: Also, since a lot of my menubutton options are shown as acronyms when selected (for space reasons), I’ve created a way to show a tooltip each time I pick an option without posting the full cascade (in the cascade you could see the full option instead of the acronym).

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

binding drop-down-menu key navigation tkinter
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: how to get and read an xml file in a zip file using xml.etree

02/04/2023

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.