SpinBox Widget in Tkinter Example
In this example, below code sets up a Tkinter window with a Spinbox widget allowing users to select values from 0 to 100. When the value changes, it prints the new value. The Spinbox has customizable appearance options like width, relief, and color, and it’s placed in the window with padding.
import tkinter as tk
def on_spinbox_change():
value = spinbox.get()
print("Value changed to:", value)
root = tk.Tk()
root.geometry("300x200")
# Creating a Spinbox
spinbox = tk.Spinbox(root, from_=0, to=100, width=10, relief="sunken", repeatdelay=500, repeatinterval=100,
font=("Arial", 12), bg="lightgrey", fg="blue", command=on_spinbox_change)
# Setting options for the Spinbox
spinbox.config(state="normal", cursor="hand2", bd=3, justify="center", wrap=True)
# Placing the Spinbox in the window
spinbox.pack(padx=20, pady=20)
root.mainloop()
Output
Python Tkinter – SpinBox
The Spinbox widget in Tkinter is a numerical input field that allows users to select a value from a predefined range by either typing directly into the widget or by using up and down arrow buttons to increment or decrement the value.
Note: For more reference, you can read our article: