If you want a key to invoke it, then you probably need to shift focus
to the button you want to be the default. Look up the 'focus' command.
But the default Tk bindings invoke the focused button using space, not
Enter, so you might also need to add a binding to the Enter key.
Look up the default Tk bindings for buttons and see how Tk does the
space bar binding, you can copy that one and connect it to Enter.
Hello,
I have several buttons in a row and I would like one of the to be the
default so that the Enter key will invoke it. The user can tab over to
the other buttons to press Enter too.
Normally, there is a slight visual cue to the default button. I tried "-default active", "-activebackground/-activeforeground", and several
others.
How do I achieve this?
Look up the default Tk bindings for buttons and see how Tk does the
space bar binding, you can copy that one and connect it to Enter.
Look up the default Tk bindings for buttons and see how Tk does the
space bar binding, you can copy that one and connect it to Enter.
X11/Linux/8.6.11:
$ rlwrap wish
% foreach i {1 2 3 4 5} { button .b$i -text .b$i ; pack .b$i -side left }
% focus .b4
When I hover over the window (I have Fvwm2 set for 'focus follows
mouse' mode) button .b4 has a darker border (and if I hit space while
the window is focused, button 4 is pressed).
See https://postimg.cc/Js4HD3VV
On 10/31/2022 9:57 PM, Rich wrote:
If you want a key to invoke it, then you probably need to shift focus
to the button you want to be the default. Look up the 'focus' command.
But the default Tk bindings invoke the focused button using space, not
Enter, so you might also need to add a binding to the Enter key.
My mistake: I should have said space not Enter.
Look up the default Tk bindings for buttons and see how Tk does the
space bar binding, you can copy that one and connect it to Enter.
My question was not about the behavior which works just fine. Rather my question was that on my buttons, there is no visual indication as to
which one would be invoked if I hit the space bar. [focus] on the frame
or the any of buttons themselves doesn't seem to provide any visual clue.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (0 / 16) |
| Uptime: | 169:26:47 |
| Calls: | 12,097 |
| Calls today: | 5 |
| Files: | 15,003 |
| Messages: | 6,517,837 |