Version 12 of ttk::spinbox

Updated 2017-03-27 13:29:06 by badchicken

Summary

New command in Ttk (since tk8.5.9).

See Also

pure Tcl version

Description

Introduced in Tk version 8.5.9.

Unlike spinbox, the -from option does not cause the value to be set, so that must be done explicitly. See Tk ticket, 2013-08-12 .

Font

HaO 2011-05-13 The spinbox font may be set using the -font option. In Windows Vista theme, there might appear a gap between the spinbuttons.

pack [ttk::spinbox .s -font {size 20}]

ttk_spinbox_fontsize_20.png

In the clam or alt theme, the style option -arrowsize may be used to change the button sizes:

ttk::style theme use clam
ttk::style configure custom.TSpinbox -arrowsize 20
pack [ttk::spinbox .s -font {size 20} -style custom.TSpinbox]

Hexadecimal Display

AMG: If you want a hexadecimal display, you need to bind to the <<Decrement>> and <<Increment>> virtual events. The bind scripts must invoke [break] to inhibit normal spinbox processing, or else your hexadecimal values will be "corrected" back to the minimum.

proc spinhex {win dir} {
    if {![scan [$win get] %x val]} {
        set val [$win cget -from]
    } else {
        incr val [expr {$dir * [$win cget -increment]}]
        if {[$win cget -wrap]} {
            set val [ttk::spinbox::Wrap $val [$win cget -from] [$win cget -to]]
        } else {
            set val [ttk::spinbox::Limit $val [$win cget -from] [$win cget -to]]
        }
    }
    $win set [format [$win cget -format] $val]
}
ttk::spinbox .sb -from 0 -to 255 -wrap 1 -font fixed -format "% 2X" -textvariable sb
bind .sb <<Decrement>> {spinhex %W -1; break}
bind .sb <<Increment>> {spinhex %W +1; break}
pack .sb
set sb [format [.sb cget -format] 10]

badchicken - 2017-03-27 13:29:06

I have an strange behavior that it invokes the command without stop. I write the next code in the wish8.6 console:

ttk::spinbox .sb -from 0 -to 10000 -command [list ::danitest]
grid .sb
proc ::danitest {} {
    puts "inside"
    tkwait variable ::danivar
    puts "outside"
}

Then, I do a single click on any arrow. The command is invoked and I can read the message "inside". Now, the process is waiting to the change of my variable danivar. In this momment, I write in the console the next code:

set ::danivar 1

and when I press enter I see that the message outside is shown, and some milliseconds later, the event is recalled (and I can read again the message "inside"). This behaviour doesn't stops.

I don't know if it is my fault or there is an error. I have the same behaviour if I use the command error instead of tkwait.