When to use the Spinbox Widget
The Spinbox widget can be used instead of an ordinary Entry, in cases where the user only has a limited number of ordered values to choose from.
Note that the spinbox widget is only available in Python 2.3 and later when linked against Tk 8.4 or later. Also, note that several Tk spinbox methods appear to be missing from the Tkinter bindings in Python 2.3.
Here is the detailed tutorial of tkinter
Patterns
The spinbox behaves pretty much like an ordinary Entry widget. The main difference is that you can specify what values to allow, either as a range, or using a tuple.
from tkinter import *
master = Tk()
w = Spinbox(master, from_=0, to=10)
w.pack()
mainloop()
You can specify a set of values instead of a range:
w = Spinbox(values=(1, 2, 4, 8, 10))
w.pack()
Reference
Spinbox(master=None, **options) (class)
A spinbox widget.master
Parent widget.
config(**options)
Modifies one or more widget options. If no options are given, the method returns a dictionary containing all current option values.
**options
Widget options
activebackground = Default is system specific. (activeBackground/Background)
background = Default is system specific. (background/Background)
bd = Same as borderwidth
bg = Same as background
borderwidth = Widget border width. The default is system specific, but is usually a few pixels. (borderWidth/BorderWidth)
buttonbackground = Button background color. Default is system specific. (Button.background/Background)
buttoncursor = Cursor to use when the mouse pointer is moved over the button part of this widget. No default value. (Button.cursor/Cursor)
disabledbackground = The background color to use when the widget is disabled. The default is system specific. (disabledBackground/DisabledBackground)
disabledforeground = The text color to use when the widget is disabled. The default is system specific. (disabledForeground/DisabledForeground)
Some Commands of Spinbox
delete(first, last=None)
Deletes one or more characters from the spinbox.
get()
Returns the current contents of the spinbox.
Returns: The widget contents, as a string.
icursor(index)
Moves the insertion cursor to the given index.
This also sets the INSERT index.indexWhere to move the cursor.
identify(x, y)
Identifies the widget element at the given location.
Returns: One of “none”, “buttondown”, “buttonup”, or “entry”.
index(index)
Gets the numerical position corresponding to the given index.
Returns: The corresponding numerical index.
insert(index, text)
Inserts text at the given index. Use insert(INSERT, text) to insert text at the cursor, insert(END, text) to append text to the spinbox.
selection_clear()
Clears the selection.