扫码一下
查看教程更方便
tkinter scale 控件,用户可以通过移动沿此 scale 控件的滑块按钮从设定范围值选择数值的控件。
你可以指定最小值和最大值以及 scale
的分辨率。与 entry 控件相比,scale 提供有界的数值。
import tkinter as tk
app = tk.tk()
app.geometry('300x200')
app.title("basic scale")
scaleexample = tk.scale(app, from_=0, to=10)
scaleexample.pack()
app.mainloop()
scaleexample = tk.scale(app, from_=0, to=10)
from_
指定范围的最小值,to
指定范围的最大值。
import tkinter as tk
app = tk.tk()
app.geometry('300x200')
app.title("tkitner scale example")
scaleexample = tk.scale(app,
orient='horizontal',
resolution=0.1,
from_=0,
to=10)
scaleexample.pack()
app.mainloop()
scaleexample = tk.scale(app,
orient='horizontal',
resolution=0.1,
from_=0,
to=10)
orient='horizontal'
tkinter scale 的默认方向是竖直的,如第一个示例所示。你需要指定 scale
的 orient 属性为 horizontal,从而得到一个 tkinter 水平的 scale。
resolution=0.1
可以通过修改 scale 的 resolution 来更改 scale 的分辨率,其默认值为 1。