Tkinter 之Scale滑块标签
一、参数说明
| 语法 | 作用 |
|---|---|
| Scale(window, label="滑块") | 滑块标题 |
| Scale(window, label="滑块", from_=0) | 滑块最小值为0 |
| Scale(window, label="滑块", to=100) | 滑块最大值为100 |
| Scale(window, label="滑块", length=200) | 滑块长度为200 |
| Scale(window, label="滑块", orient = tk.HORIZONTAL) | 滑块水平方向显示 |
| Scale(window, label="滑块", resolution=0.01) | 滑块值的精度为0.01 |
| Scale(window, label="滑块", digits = 8) | 设置显示的位数为8 |
| Scale(window, label="滑块", command=select) | 滑动时的回调 |
| scale.get() | 获取当前滑块位置的值 |
| scale.set(10) | 设置滑块的值 |
二、代码示例
import tkinter as tk window = tk.Tk()
# 设置窗口大小
winWidth = 600
winHeight = 400
# 获取屏幕分辨率
screenWidth = window.winfo_screenwidth()
screenHeight = window.winfo_screenheight() x = int((screenWidth - winWidth) / 2)
y = int((screenHeight - winHeight) / 2) # 设置主窗口标题
window.title("Scale参数说明")
# 设置窗口初始位置在屏幕居中
window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
# 设置窗口图标
window.iconbitmap("./image/icon.ico")
# 设置窗口宽高固定
window.resizable(0, 0) """scale参数. Valid resource names: activebackground, background, bigincrement, bd,
bg, borderwidth, command, cursor, digits, fg, font, foreground, from,
highlightbackground, highlightcolor, highlightthickness, label,
length, orient, relief, repeatdelay, repeatinterval, resolution,
showvalue, sliderlength, sliderrelief, state, takefocus,
tickinterval, to, troughcolor, variable, width."""
def select(v):
print(v)
# 创建一个1到100的滑块, 精度为0.01, 显示的最大位数为8
scale = tk.Scale(window, label="滑块", length = 400, from_=1, to = 100, bg="#bbb", fg = "#f00", orient = tk.HORIZONTAL, command=select, resolution=0.01, digits = 8)
scale.pack() def getScaleValue():
print(scale.get()) def setScaleValue():
scale.set(10)
tk.Button(window, text="get value", width=30, pady=5, command=getScaleValue).pack()
tk.Button(window, text="set value", width=30, pady=5, command=setScaleValue).pack()
window.mainloop()
三、效果图

Tkinter 之Scale滑块标签的更多相关文章
- tkinter Scale滑块
鼠标拖动和绑定鼠标滚轮移动: import threading from tkinter import * root = Tk() v = StringVar() s1 = Scale(root,fr ...
- tkinter中scale拖拉改变值控件(十一)
scale拖拉改变值控件 使用户通过拖拽改变值 简单的实现: import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya. ...
- Python3 tkinter基础 Scale orient 横竖 resolution单步步长 length 长度 tickinterval 指示刻度
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Tkinter 之ScrollBar滚动条标签
一.参数说明 参数 作用 background (bg) 设置背景颜色 borderwidth (bd) 指定边框宽度,通常是 2 像素 cursor 指定当鼠标在上方飘过的时候的鼠标样式 orie ...
- Tkinter 之NoteBook选项卡标签
一.参数说明 参数 作用 width 选项卡宽度,单位像素 height 选项卡高度 cursor 鼠标停留的样式 padding 外部空间填充,是个最多4个元素的列表 style 设置menubo ...
- Tkinter 之ListBox列表标签
一.参数说明 参数 作用 background (bg) 设置背景颜色 borderwidth (bd) 指定 Listbox 的边框宽度,通常是 2 像素 cursor 指定当鼠标在 Listbo ...
- Tkinter 之Menu菜单标签
一.参数说明 语法 作用 MenuBar = tk.Menu(window) 创建一个菜单栏 fileBar = tk.Menu(MenuBar, tearoff=0) 创建一个菜单项,不分窗. Me ...
- Tkinter 之Entry输入框标签
一.参数说明 语法 作用 Entry(root,width=20) 组件的宽度(所占字符个数) Entry(root,fg='blue') 前景字体颜色 Entry(root,bg='blue') 背 ...
- Tkinter教程之Scale篇
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811313 '''Tkinter教程之Scale篇'''#Scale为输出限定范围的数字区间, ...
随机推荐
- 关于Vue中,使用watch同时监听两个值的实现方法
1. 先在computed中,用需要监听的两个值(start.end)定义一个对象(dateRange) computed: { dateRange () { const { start, end } ...
- element-ui 文件上传
<el-form-item> <el-upload ref="upload" class="upload-demo" :action=&quo ...
- 浅谈sqoop
1.sqoop的概述a.sqoop 是一款工具,是appche 旗下的一款工具,主要是负责 hadoop与RDBMS之间的数据迁移,即从hadoop 文件系统 导出数据到RDBMS,从RDBMS导入数 ...
- mysql案例分析
工作中,需要设计一个数据库存储,项目的需求大致如下: (1)对于每个用户,需要存储一个或多个库, 每个库, 由一个用户标识来标识,这里成为clientFlag. (2) 对于每一个库,结构如下: 1) ...
- 定制ubuntu镜像
使用ubuntu server 18.04 lts版镜像 作为源镜像定制目标镜像, 工具cubic, 定制目标镜像, 使得一些服务装机后即可使用,例如redis, mysql, monggodb ,s ...
- [nginx] nginx使用SNI功能的方法
SNI是什么 在使用TLS的时候,http server希望根据HTTP请求中HOST的不同,来决定使用不同的证书. SNI细节 由于HTTP的HOST字段在HTTP GET中.而TLS的握手以及证书 ...
- 创建yum私有库
简述 在Linux系统中安装软件的方法有三种,分别是rpm软件包安装.yum源安装与源代码编译安装,在用rpm软件包安装软件时会经常出现依赖性问题,导致安装繁琐,用源代码编译安装就更不用说了,相信 ...
- 《Python编程:从入门到实践》第二章 变量和简单数据类型 习题答案
#2.1 print("Hello world!"); #2.2 message="Hello,Python!"; print(message); #2.3 n ...
- 报错:ipython 6.5.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll have prompt-toolkit 2.0.15 which is incompatible.
pip install imagededup 时,报错:ipython 6.5.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but y ...
- Python中的时间
coding:utf-8 from time import strftime, localtime import time print(time.time()) time1=strftime('%Y- ...