Tkinter Tutorial - Scale

Jinku Hu Feb 15, 2024
  1. Tkinter Scale Example
  2. Tkinter Scale Orientation and Resolution
Tkinter Tutorial - Scale

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()

Tkinter Scale Horizontal and Different Resolution

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.

Author: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn Facebook