How to automatically update `tk.Label` when the value of `tk.Scale` changes? How to automatically update `tk.Label` when the value of `tk.Scale` changes? tkinter tkinter

How to automatically update `tk.Label` when the value of `tk.Scale` changes?


If the scale and label share a common variable, the label will automatically update. You can call the set method of the variable to provide a default value of the scale.

Here's a simple example:

import tkinter as tkroot = tk.Tk()scalevar = tk.IntVar()scalevar.set(50)scale = tk.Scale(root, from_=0, to=100,                  variable=scalevar, orient="horizontal")label = tk.Label(root, textvariable=scalevar)scale.pack(side="top", fill="x", expand=True)label.pack(side="top", fill="x", expand=True)root.mainloop()