Version 11 of ttk::spinbox

Updated 2014-04-17 03:13:28 by RLE


New command in Ttk (since tk8.5.9).

See Also

pure Tcl version


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 .


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}]


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]