TUTORIAL · Tkinter
Tkinter Tutorial - Scale
This tutorial section introduces the scale in Python Tkinter.
A Scale is the widget that user could select a numerical value from the range of values by moving a slider knob along the scale.
You could specify the minimum and maximum values and also the resolution of the scale. The scale provides a bounded numerical value compared to a Entry widget.
Tkinter Scale Example
import tkinter as tk
app = tk.Tk()
app.geometry("300x200")
app.title("Basic Scale")
scaleExample = tk.Scale(app, from_=0, to=10)
scaleExample.pack()
app.mainloop()
scaleExample = tk.Scale(app, from_=0, to=10)
from_ specifies the minimum value, and to specifies the maximum value of the range.
Tkinter Scale Orientation and Resolution
import tkinter as tk
app = tk.Tk()
app.geometry("300x200")
app.title("Tkitner Scale Example")
scaleExample = tk.Scale(app, orient="horizontal", resolution=0.1, from_=0, to=10)
scaleExample.pack()
app.mainloop()
scaleExample = tk.Scale(app, orient="horizontal", resolution=0.1, from_=0, to=10)
orient = "horizontal"
The default orientation of Tkinter scale is vertical as shown in the first example. You need to specify the orient attribute of scale to be horizontal to get a horizontal Tkinter scale.
resolution = 0.1
The resolution of the scale could be modified by resolution option that has the default value of 1.