Tk - Spinbox Widget



Spinbox widget allows users to choose numbers or arbitrary values. The syntax for spinbox widget is shown below.

spinbox spinboxName options

Options

The options available for the spinbox widget are listed below in table.

Sr.No. Syntax & Description
1

-background color

Used to set background color for widget.

2

-borderwidth width

Used to draw with border in 3D effects.

3

-font fontDescriptor

Used to set font for widget.

4

-foreground color

Used to set foreground color for widget.

5

-from number

Range start value for spinbox.

6

-increment number

Range increment value for spinbox.

7

-relief condition

Sets the 3D relief for this widget. The condition may be raised, sunken, flat, ridge, solid, or groove.

8

-textvariable varName

Variable associated with the widget. When the text of widget changes, the variable is set to text of widget.

9

-to number

Range end value for spinbox.

10

-values array

Arbitrary values for spinbox widget.

11

-width number

Sets the width for widget.

A simple example for spinbox widget is shown below −

#!/usr/bin/wish

set mylist [list C C++ Lua Tcl]
pack [spinbox .s1  -textvariable spinval1 -values $mylist -background yellow -borderwidth
   5 -font {Helvetica -18 bold} -foreground red -width 40  -relief ridge]
pack [spinbox .s2  -textvariable spinval2 -from 1.0 -to 100.0 -increment 5 -background
   yellow -borderwidth 5 -font {Helvetica -18 bold} -foreground red -width 40
   -relief ridge]

When we run the above program, we will get the following output −

Spinbox Example
tk_mega_widgets.htm
Advertisements