Tkinter 教程 - Scale 控件
Jinku Hu
2024年2月15日
Tkinter
Tkinter Scale
Tkinter Scale 控件,用户可以通过移动沿此 Scale 控件的滑块按钮从设定范围值选择数值的控件。
你可以指定最小值和最大值以及 Scale 的分辨率。与 Entry 控件相比,Scale 提供有界的数值。
Tkinter 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 指定范围的最大值。
Tkinter Scale 方向和分辨率
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。
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
