如何从 Tkinter 滑块(“Scale")中获取价值? [英] How to Get Value Out from the Tkinter Slider ("Scale")?
本文介绍了如何从 Tkinter 滑块(“Scale")中获取价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,这是我的代码,当我运行它时,滑块的值出现在滑块上方,我想知道有没有办法把那个值取出来?也许让 a=那个值.;)
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()
推荐答案
要获取修改后的值,请将函数与参数 command
关联.此函数将接收当前值,因此您只需使用它即可.另请注意,在您的代码中,您有 cline3 = Scale(...).pack()
.cline3
在这种情况下总是 None,因为这是 pack()
返回的内容.
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()
这篇关于如何从 Tkinter 滑块(“Scale")中获取价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文