Scale

Scale刻度组件。

当你希望用户输入某个范围内的一个数值,使用scale组件可以很好的代替Entry组件。

用法: 创建一个指定范围的Scale组件其实非常容易,你只需要指定from和to两个选项即可。

但是由于,from本身是Python的关键字,所以为了区分需要在后边紧跟一个下划线:from_

 1 from tkinter import *
 2 root = Tk()
 3 
 4 s1 = Scale(root,from_=0,to=42)
 5 s1.pack()
 6 
 7 s2 = Scale(root,from_=0,to=200,orient=HORIZONTAL)
 8 s2.pack()
 9 
10 mainloop()
 1 #使用get可以获取两个滑块的位置
 2 from tkinter import *
 3 master=Tk()
 4 
 5 s1= Scale(master,from_=0,to=100)
 6 s1.pack(padx=10,pady=10)
 7 
 8 s2 = Scale(master,from_=0,to=50,orient=HORIZONTAL)
 9 s2.pack(padx=10,pady=10)
10 
11 def getposition():
12     print(s1.get(),s2.get())
13 
14 b = Button(master,text='获取位置',command=getposition)
15 b.pack()
16 
17 mainloop()
 1 #使用resolution控制步长,即每一步走多长,通过tickinterval设置刻度,每隔几个是一个刻度
 2 from tkinter import *
 3 master = Tk()
 4 s1= Scale(master,from_=0,to=100,resolution=5,
 5           length=200,tickinterval=5,orient=VERTICAL)
 6 s1.pack()
 7 
 8 s2 =Scale(master,from_=0,to=200,resolution=10,
 9           length=1000,tickinterval=5,orient=HORIZONTAL)
10 s2.pack()
11 
12 mainloop()
原文地址:https://www.cnblogs.com/themost/p/6770290.html