Tkinter get and set the Scale value of Scale
When designing a GUI program, you can use the set() method to set the value of the scale, and you can use the get() method to get the value of the scale.
Tkinter get and set the Scale value of Scale Example#1
Use set() to set the initial value of the scale and get() to get the scale value. The vertical and horizontal scale values can be listed in the Python Shell window when the Print button is clicked.
from tkinter import *
def printInfo():
print("Vertical scale value = %d, Horizontal scale value = %d" % (sV.get(),sH.get()))
root = Tk()
root.title("apidemos.com") # Title of the window
sV = Scale(root,label="Vertical Scale",from_=0,to=10) # Establishing vertical scale
sV.set(5) # Set the initial value of vertical scale to 5
sV.pack()
sH = Scale(root,label="Horizontal Scale",from_=0,to=10,
length=300,orient=HORIZONTAL)
sH.set(3)
sH.pack()
Button(root,text="Print the values on both Scales",command=printInfo).pack()
root.mainloop()
Output:
Click the Print button to get the following results.