How to get the value from the Tkinter ("Scale") slider?

So, here is the code that I have, and when I run it, the value of the slider appears above the slider, I wonder if there is a way to get this value? Perhaps let a = this value .;)

from Tkinter import * control=Tk() control.title("Control") control.geometry("350x200+100+50") cline0=Label(text="").pack() cline1=Label(text="Speed").pack() cline3=Scale (control,orient=HORIZONTAL,length=300,width=20,sliderlength=10,from_=0,to=1000,tickinterval=100).pack() cline4=Label(text="").pack() control.mainloop() 
+4
source share
2 answers

To get the value when it changes, map the function to the command parameter. This function will get the current value, so you just work with it. Also note that your code has cline3 = Scale(...).pack() . cline3 always not None in this case, as this returns pack() .

 import Tkinter def print_value(val): print val root = Tkinter.Tk() scale = Tkinter.Scale(orient='horizontal', from_=0, to=128, command=print_value) scale.pack() root.mainloop() 
+11
source

Call the .get() method on the slider to read the current value:

 print cline3.get() 

See the Tkinter widget documentation .

+4
source

All Articles