The docs for Ttk::button
's -default
option state that it's supposed to be used in dialog boxes, however the only dialog box function I know of is tk_dialog, which can't take buttons as arguments but only the button titles.
Does anyone have a working example of a Ttk::button
with it's -default
option set to active
, where upon running the app and the user hitting the enter
key this button is invoked? Here are my attempts:
I've attempted to lay out a button directly in the main window:
package require Tk
ttk::button .button -text "text" -default active -command "puts sometext"
bind .button <Return> { .button invoke }
pack .button
Pressing enter
does nothing by default, I would first have to tab
to select the button and then hitting enter
will work.
I've also tried injecting buttons into tk_dialog
, thinking the following might work:
package require Tk
tk_dialog .dg "Title" "Question" "" "" \
[ttk::button .button1 -text "Yes" -default disabled] \
[ttk::button .button2 -text "No" -default active]
But that just creates two buttons ".button1" and ".button2", and neither of them are the default-selected one. (this makes sense since the 4th parameter is empty). tk_dialog
itself can specify the default button, but I cannot pass custom buttons to it, it only seems to accept strings for the button names.
The reason I'm asking this is because I'm writing a language binding to Tk and have to figure out which settings should be exposed. I've looked at Tkinter
for Python, and it doesn't seem to wrap the -default
option for buttons. Is this option ever used in Tk
, and if so could you give me a proper working example? Thanks.