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.
Example
#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 win.geometry("750x250") #Set the default value for SpinBox my_var= StringVar(win) my_var.set("1.0") #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) win.mainloop()
Output
Executing the above code will display a window that contains a spinbox having a default value set to 1.0.