Python Tkinter Spinbox


In this tutorial, we will learn about Python Tkinter SpinboxTkinter 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()

Various possible options in Python Tkinter Spinbox:

OPTION DESCRIPTION
activebackground This option is used to set the colour of the slider and arrowheads on mouse hover.
bg This option is used to set the colour of the slider and arrowheads.
bd This option is used to set the size of the border around the widget.
command This option is used to set the function to call on the move of the scrollbar.
cursor This option helps us to set the style of cursor like an arrow, dot etc
disabledbackground This option is used to set the background colour of the widget when the widget is disabled.
disabledforeground This option is used to set the background colour of the text in widget when the widget is disabled.
fg This option is used to set the foreground colour(text colour) of the widget.
font This option is used to set font type in the widget.
format This 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.
justify This option is used to the alignment of the widget. By default, it is LEFT.
relief This helps us to set the 3D style text which is by default is relief=SUNKEN.
state This option is used to set the state of the widget. such as NORMAL, DISABLED, or “readonly”. By default it is NORMAL.
textvariable This option is used to set the text variable to the widget. There is no default value for this widget.
to This option is used to set the last value of the valid values.
validate This option is used to set the validation mode. By default, it is NONE.
validatecommand This option is used to set validate callback.
values This option is used to set a tuple to widget(Tuple which contain valid values).
width This helps us to set the width of the widget. By default, it is 20.
wrap This option helps us to wrap around and down button.
xscrollcommand This 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.

METHODS DESCRIPTION
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:

Please share this page on social media with your friends..

Facebook share Twitter Linkedin share