一、参数说明

语法 作用
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()

三、效果图

最新文章

  1. html5的audio在safari(windows)中无效
  2. iOS 疑难杂症— — 收到推送显示后自动消失的问题
  3. 解决:j-link V8下载器灯不亮,无法正常烧写固件
  4. [js开源组件开发]模拟下拉选项框select
  5. RDS记录
  6. 磁盘IO的性能指标
  7. volatile 关键字
  8. 【Spring】Spring系列5之Spring支持事务处理
  9. Winform TreeView 节点拖动
  10. xml<>编译
  11. Chapter 11. Frame, MainWindow, and Toplevel Widgets 框架,主窗体,顶级部件
  12. Ubuntu Gnome下如何改动应用的图标icon
  13. linux学习(一个) 在unbuntu通过添加新的用户
  14. 解决Only the original thread that created a view hierarchy can touch its views
  15. Python 学习笔记大纲
  16. lucene全文检索基础
  17. mysql复习
  18. BAI度 内部资料!Python_Threads多线程
  19. centos7开放及查看端口
  20. redis 基本指令

热门文章

  1. 简介:google ctemplate:简单易用的文字模板(转载)
  2. Python中闭包的原理
  3. 前端相关UED团队和个人博客整理
  4. 【亲测有效】vs2017无法断点
  5. Windows Server 2012 R2上安装.Net4.6.1出错
  6. Android简单闹钟设置
  7. 如何使用python自定义命令
  8. javascript动态添加html节点
  9. JMeter测试clickhouse
  10. unittest管理测试用例