Tkinter 教程 - Scale 控件

Jinku Hu 2023年1月30日 2019年12月10日
  1. Tkinter SCale 例子
  2. Tkinter Scale 方向和分辨率
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()

Tkinter Scale 方向和分辨率

scaleExample = tk.Scale(app,
                        orient='horizontal',
                        resolution=0.1,
                        from_=0,
                        to=10)
orient='horizontal'

Tkinter Scale 的默认方向是竖直的,如第一个示例所示。你需要指定 scaleorient 属性为 horizontal,从而得到一个 Tkinter 水平的 Scale

resolution=0.1

可以通过修改 Scaleresolution 来更改 Scale 的分辨率,其默认值为 1

Author: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn