The Spinbox widget is a variant of the standard Tkinter Entry widget, which can be used to select from a fixed number of values.
SyntaxHere is the simple syntax to create this widget −
w = Spinbox( master, option, ... )Parameters
master − This represents the parent window.
options − Here is the list of most commonly used options for this widget. These options can be used as key-value pairs separated by commas.
activebackground
The color of the slider and arrowheads when the mouse is over them.
2bg
The color of the slider and arrowheads when the mouse is not over them.
3bd
The width of the 3-d borders around the entire perimeter of the trough, and also the width of the 3-d effects on the arrowheads and slider. Default is no border around the trough, and a 2-pixel border around the arrowheads and slider.
4command
A procedure to be called whenever the scrollbar is moved.
5cursor
The cursor that appears when the mouse is over the scrollbar.
6disabledbackground
The background color to use when the widget is disabled.
7disabledforeground
The text color to use when the widget is disabled.
8fg
Text color.
9font
The font to use in this widget.
10format
Format string. No default value.
11from_
The minimum value. Used together with to to limit the spinbox range.
12justify
Default is LEFT
13relief
Default is SUNKEN
14repeatdelay
Together with repeatinterval, this option controls button autorepeat. Both values are given in milliseconds.
15repeatinterval
See repeatdelay.
16state
One of NORMAL, DISABLED, or "readonly". Default is NORMAL.
17textvariable
No default value.
18to
See from.
19validate
Validation mode. Default is NONE.
20validatecommand
Validation callback. No default value.
21values
A tuple containing valid values for this widget. Overrides from/to/increment.
22vcmd
Same as validatecommand.
23width
Widget width, in character units. Default is 20
24wrap
If true, the up and down buttons will wrap around.
25xscrollcommand
Used to connect a spinbox field to a horizontal scrollbar. This option should be set to the set method of the corresponding scrollbar.
MethodsSpinbox objects have these methods −
Sr.No. Methods and Description 1delete(startindex [,endindex])
This method deletes a specific character or a range of text.
2get(startindex [,endindex])
This method returns a specific character or a range of text.
3identify(x, y)
Identifies the widget element at the given location.
4index(index)
Returns the absolute value of an index based on the given index.
5insert(index [,string]...)
This method inserts strings at the specified index location.
6invoke(element)
Invokes a spinbox button.
ExampleTry the following example yourself −
from Tkinter import * master = Tk() w = Spinbox(master, from_=0, to=10) w.pack() mainloop()
When the above code is execduted, it produces the following result −
python_gui_programming.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4