How do I get the value of a Scale (slider) in tkinter?
Call .get() on the slider for the current value, or give it a command to be told on every move. Those two routes do not hand you the same type, which is where the confusion starts.
import tkinter as tk
root = tk.Tk()
volume = tk.Scale(root, from_=0, to=100, orient="horizontal")
volume.pack()
def apply_it():
print("volume", volume.get()) # a number
tk.Button(root, text="Apply", command=apply_it).pack()
root.mainloop() The callback is handed a string
A command on a Scale is called with the new position as its only argument, and Tk passes it as text — "42" on a plain Scale, "42.0" on a ttk one. Using it directly in arithmetic raises a TypeError, which is confusing when .get() on the very same widget returns a number.
Convert the argument, or ignore it and call .get() inside the handler. Either is fine; mixing them up is what costs the afternoon.
def on_move(value):
print(float(value) + 1) # convert what you are handed
print(volume.get() + 1) # or ask the widget insteadWhole numbers or decimals
On a classic tk.Scale, resolution decides the step and the type you get back: the default of 1 gives integers, and resolution=0.1 gives floats. It also controls where the slider is allowed to land, so it is the option to reach for when a value must stay on a grid.
tk.Scale(root, from_=0, to=1, resolution=0.1) # 0.0, 0.1, 0.2 …tk.Scale and ttk.Scale are not the same widget
The themed ttk.Scale looks native and is the one ttkbootstrap styles, but it drops several options the classic widget has. There is no resolution and no showvalue, and .get() always returns a float — so a themed slider that must report whole numbers needs rounding in your own code.
The classic tk.Scale shows its current number above the trough by default and can be told not to with showvalue=False. If you want that readout on a themed slider, put a Label next to it and update it from the callback.
import tkinter.ttk as ttk
s = ttk.Scale(root, from_=0, to=100)
round(s.get()) # themed sliders hand back floats Doing it without the lookup
Drag a Scale on, set the range in the inspector, and pick the toolkit afterwards — the export writes the classic or themed widget to match, so the difference above is handled for you. Handler stubs come with the argument already in the signature, which is the half people forget.
Lay the window out visually and read the generated Python as you go.
Open the tkinter designer →