Python GUI 08----Scale
来源:互联网 发布:java底层书籍 编辑:程序博客网 时间:2024/05/17 03:36
Scale为输出限定范围的数字区间,可以为之指定最大值,最小值及步距值。Scale组件默认为垂直,最大值100,最小值0,步距为1
1.创建一个Scale
from tkinter import *root = Tk()Scale(root).pack()root.mainloop()
2.改变缺省值
from tkinter import *root = Tk()Scale(root, from_ = -500, #设置最大值 to = 500, #设置最小值 resolution = 5, #设置步距值 orient = HORIZONTAL #设置水平方向 ).pack()root.mainloop()
3.Scale绑定变量
from tkinter import *root = Tk()v = StringVar()Scale(root, from_ = 0, #设置最小值 to = 100.0, #设置最大值 resolution = 0.0001, #设置步距值 orient = HORIZONTAL, #设置水平方向 variable = v #绑定变量 ).pack()print (v.get()) #Scale的值一致root.mainloop()
4.使用回调函数打印当前的值
from tkinter import *root = Tk()def printScale(text): print ('text = ',text) print ('v = ',v.get())v = StringVar()Scale(root, from_ = 0, #设置最小值 to = 100.0, #设置最大值 resolution = 0.0001, #设置步距值 orient = HORIZONTAL, #设置水平方向 variable = v, #绑定变量 command = printScale #设置回调函数 ).pack()print (v.get())root.mainloop()这个回调函数有一个参数,这个值是当前的Scale的值,每移动一个步距就会调用一次这个函数,只保证最后一个肯定会调用,中间的有可能不会调用,通过上例可以看到二者的值是完全一样的。
5.设置Scale的标签属性label
from tkinter import *root = Tk()Scale(root, from_ = 0, to = 100.0, orient = HORIZONTAL, label = 'choice:', #设置标签值 ).pack()root.mainloop()
6.设置/取得Scale的值
from tkinter import *root = Tk()sl = Scale(root)sl.set(50) #将Scale的值设置为50print (sl.get()) #打印当前的Scale的值sl.pack()root.mainloop()
1 0
- Python GUI 08----Scale
- python的GUI,Label和Scale联合使用
- Python GUI
- python gui
- Python GUI
- Python GUI
- python-gui
- python GUI
- Python Tkinter编程 Scale控件
- Scale
- Scale
- Scale
- Large scale machine learning in Python
- Python GUI库
- Python的GUI编程
- GUI Programming in Python
- 6.python GUI 引库报错
- Python GUI (Tkinter)
- codeforces535C:Tavas and Karafs(二分)
- C-回文[顺序表]
- LeetCode 104 Maximum Depth of Binary Tree
- 如何通过dba_hist_active_sess_history分析历史数据库性能问题
- MyBatis学习总结(一)——MyBatis快速入门
- Python GUI 08----Scale
- Html5系列(十八) canvas 径向渐变2
- Multiplication Puzzle POJ 1651
- 33-判断一个字符串中出现的字符的个数
- Java IO流
- C#截取字符串的几种方式
- Html5系列(十六)web前端开发规范文档
- 解决 eclipse 找不到字体 Courier New 字体
- Html5系列(十七) canvas 对角线渐变