jarvisteach / appJar

Simple Tkinter GUIs in Python
http://appJar.info
Other
613 stars 68 forks source link

Keybind Encroachment #488

Closed robertmlinden closed 6 years ago

robertmlinden commented 6 years ago

Setting a general keybind (using app.bindKey(key, func) conflicts with setting a shortcut for a menu item. That is, if a menu item shortcut is "Control-1" and a general keybind is "1", then everytime I hit "Control-1", first: the general keybind, "1", is activated (undesired), and then the shortcut keybind (yes, desired) is run.

Keybinds need to recognize when they are hit with a special key.

jarvisteach commented 6 years ago

This definitely doesn't sound right, and I'm not sure why it would happen. I'll need to have a look into it.

Could you post an example of code causing this problem, and also let me know your platform/python versions?

robertmlinden commented 6 years ago

Simplifying...

self.bindKey("1", keyPress) self.addMenuItem(... shortcut='Control-1' ...)

...

def keypress(): if key.isnumeric(): foo1()

Results: Menu Item 'Control-1' shortcut is non-responsive. Even when holding down the control key, foo1() is called.

AppJar 0.93.0 Python 3.6.6 Windows

jarvisteach commented 6 years ago

OK, I've done more digging.

Turns out the issue might be around the syntax Control-1 this doesn't create the expected binding, but instead (I think) is binding the mouse button?

Anyway, according to this: https://stackoverflow.com/questions/16082243/how-to-bind-ctrl-in-python-tkinter

You should be binding Control-Key-1

jarvisteach commented 6 years ago

Closing this as I think it's resolved.

robertmlinden commented 6 years ago

I've returned to this issue as it is once again relevant and the GUI is not responding to self.bindKey('Control-Key-1', [func]). It's still activating the self.bindKey('1', [func2]) action. Not sure what's going on?

self.bindKey("1", self.key_press_home)
self.bindKey("Control-Key-1", self.launch_file_event_1)

key_press_home is run instead of launch_file_event_1

Sorry to bother, I hope I'm not making a silly mistake.