Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get Value Out from the Tkinter Slider ("Scale")?

So, here is the code I have, and as I run it, the value of the slider bar appears above the slider, I wonder is there a way to get that value out? Maybe let a=that value. ;)

from Tkinter import *

control = Tk()
control.geometry("350x200+100+50")

scale = Scale(control,orient=HORIZONTAL,length=300,width=20,sliderlength=10,from_=0,to=1000,tickinterval=100)
scale.pack()

control.mainloop()
like image 466
user2006082 Avatar asked Jan 24 '13 19:01

user2006082


People also ask

What is tkinter scale?

The Scale widget is used to implement the graphical slider to the python application so that the user can slide through the range of values shown on the slider and select the one among them. We can control the minimum and maximum values along with the resolution of the scale.

What is IntVar () in tkinter?

Tkinter IntVar() FunctionA variable defined using IntVar() function holds integer data where we can set integer data and can retrieve it as well using getter and setter methods.

How do I use the progress bar in tkinter?

Use the ttk. Progressbar(container, orient, length, mode) to create a progressbar. Use the indeterminate mode when the program cannot accurately know the relative progress to display. Use the determinate mode if you know how to measure the progress accurately.


1 Answers

To get the value as it is modified, associate a function with the parameter command. This function will receive the current value, so you just work with it. Also note that in your code you have cline3 = Scale(...).pack(). cline3 is always None in this case, since that is what pack() returns.

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()
like image 113
mmgp Avatar answered Sep 28 '22 21:09

mmgp