When Tkinter detects a modified click event such as <Shift-Button-1>
, <Control-Button-1>
, etc. is there a way to "stub out" the modifier key and have it handled as merely <Button-1>
instead?
The only approach I can think of -- which isn't working for my use case -- is to create event bindings for the various modifiers, and then point them all to a callback that triggers the unmodified event. E.g.,
import Tkinter as tk
root = tk.Tk()
lst = tk.Listbox(root,selectmode=tk.EXTENDED)
[...geometry setup...]
def clickOnly(*args):
lst.event_generate('<Button-1>')
lst.bind('<Shift-Button-1>',clickOnly)
lst.bind('<Control-Button-1>',clickOnly)
[...other related bindings...]
tk.mainloop()
When I run this code, the shift-click etc. are intercepted by the callback but the behavioral results deviate from what the plain click would do. E.g. the shift-click gets anchored to the item at index 0 and still selects multiple items instead of just the clicked one.
Guidance on how to correct my approach would be fine, but I'm really hoping someone can point me to a different, cleaner approach -- some more direct way to have the shift, control, and other modifiers treated as if they were always false.
(Environment is Python 2.7.x, running on Windows 7/10.)
EDIT: What I'm trying to make happen is this:
- User points and clicks: Default behavior
- User points and shift-clicks: Shift ignored, default behavior for a click
- User points and control-clicks: Control ignored, default behavior for a click
- User points and alt-clicks: Alt ignored, default behavior for a click
- (you get the idea)
I.e. there any way to make Tkinter ignore the modifiers?