Tkinter Spinbox Widget Setting Default Value

Tkinter Spinbox is used to add the increment and decrement buttons to the Entry widget, making it useful to handle the numerical data of any application. A spinbox widget can be created using the Spinbox(arguments). We can set the default value for the spinbox widget by defining the Value using StringVar() object. The default value plays a vital role for any widget, as it helps you to define the bounded value.


#Import Tkinter library
from tkinter import *
from tkinter import ttk
#Create an instance of Tkinter frame or window
win= Tk()
#Set the geometry of tkinter frame
#Set the default value for SpinBox
my_var= StringVar(win)
#Create a spinbox
spinbox= ttk.Spinbox(win, from_=0.5, to=10.0, increment=0.01, textvariable=my_var)
spinbox.pack(ipadx=20, pady=20)


Executing the above code will display a window that contains a spinbox having a default value set to 1.0.

Updated on: 22-Apr-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started