Python Tkinter Spinbox

By | April 21, 2020

In this tutorial, we will learn about Python Tkinter Spinbox. Tkinter Spinbox is an entry widget which is used to ask the user to choose one from fixed values.

Syntax to add Python Tkinter Spinbox:

w = Spinbox( master, option)
  • master: This represents the parent window.
  • options: Here is the list of most commonly used options for this widget.

Example Program of Python Tkinter Spinbox:

from tkinter import *

masterWindow = Tk()

masterWindow.geometry("320x180")

spinBox = Spinbox(masterWindow, from_=1, to=10)

spinBox.pack()

mainloop()

Python Tkinter Spinbox Output:

Python Tkinter Spinbox

Various possible options in Python Tkinter Spinbox:

OPTIONDESCRIPTION
activebackgroundThis option is used to set the colour of the slider and arrowheads on mouse hover.
bgThis option is used to set the colour of the slider and arrowheads.
bdThis option is used to set the size of the border around the widget.
commandThis option is used to set the function to call on the move of the scrollbar.
cursorThis option helps us to set the style of cursor like an arrow, dot etc
disabledbackgroundThis option is used to set the background colour of the widget when the widget is disabled.
disabledforegroundThis option is used to set the background colour of the text in widget when the widget is disabled.
fgThis option is used to set the foreground colour(text colour) of the widget.
fontThis option is used to set font type in the widget.
formatThis option is used to set format string for the widget.
from_This option is used to set the starting point to show values in the widget.
justifyThis option is used to the alignment of the widget. By default, it is LEFT.
reliefThis helps us to set the 3D style text which is by default is relief=SUNKEN.
stateThis option is used to set the state of the widget. such as NORMAL, DISABLED, or “readonly”. By default it is NORMAL.
textvariableThis option is used to set the text variable to the widget. There is no default value for this widget.
toThis option is used to set the last value of the valid values.
validateThis option is used to set the validation mode. By default, it is NONE.
validatecommandThis option is used to set validate callback.
valuesThis option is used to set a tuple to widget(Tuple which contain valid values).
widthThis helps us to set the width of the widget. By default, it is 20.
wrapThis option helps us to wrap around and down button.
xscrollcommandThis option used to connect the spinbox widget to the horizontal scrollbar.

Tkinter Spinbox Methods:

After learning about various available options in Python Tkinter Spinbox Its time to check out some available methods for Tkinter Spinbox widget.

METHODSDESCRIPTION
delete(startindex [,endindex])This method used to delete a single character or the range of values between specified index numbers.
get(startindex [,endindex])This method returns a single character or the range of values between specified index numbers.
identify(x, y)This method is used to identify the widget element at the given location.
index(index)This method returns the value at the specified index number.
insert(index [,string]…)This method is used to insert a string at the specified index number.
invoke(element)This method is used to invoke the Spinbox button.
Spread the love