python tkinter资源归纳
tkinter简单功能介绍(ttk内容介绍太少,但重在全面)
csdn:tkinter详细用法(tkinter介绍比较详细,但是没有ttk部分)
csdn:tkinter详解(没有ttk)
ttk组件状态-states
state 描述 active The mouse cursor is over the widget and pressing a mouse button will cause some action to occur disabled Widget is disabled under program control focus Widget has keyboard focus pressed Widget is being pressed selected “On”, “true”, or “current” for things like Checkbuttons and radiobuttons background Windows and Mac have a notion of an “active” or foreground window. The background state is set for widgets in a background window, and cleared for those in the foreground window readonly Widget should not allow user modification alternate A widget-specific alternate display format invalid The widget’s value is invalid
ttk组件–下拉列表框(Combobox)
使用前导入模块:
from tkinter.ttk import *
var=StringVar()
var.set("python")
Combobox(root,values=["python","c++","c","java","vb"],width=10,textvariable=var).pack()
Combobox参数详解
- values :传递一个要在下拉框中显示的列表
- width、height
- postcommand:点击下拉列表框的那个箭头前发生的事件
- state:列表框状态:“normal”:默认,列表框可以手动输入值,“readonly”:不能输入值,“disabled”:列表框不可选中
- testvariable:将列表框的值绑定给一个变量
- justify:指定文本对齐方式,参数有“left”,“center”,“right”
Spinbox–entry的子类
Option | Description |
---|---|
from_ | |
to | |
increment | Float value. Specifies the amount which the increment/decrement buttons change the value. Defaults to 1.0. |
values | Sequence of string or float values. If specified, the increment/decrement buttons will cycle through the items in this sequence rather than incrementing or decrementing numbers. |
wrap | Boolean value. If True , increment and decrement buttons will cycle from the to value to the from value or the from value to the to value, respectively. |
format | String value. This specifies the format of numbers set by the increment/decrement buttons. It must be in the form “%W.Pf”, where W is the padded width of the value, P is the precision, and ‘%’ and ‘f’ are literal. |
command | 每当上升箭头或下降箭头被按下时就会执行此命令 |
Progressbar–进度条
from tkinter import *
from tkinter import ttk
import time
def manu_increment(*args):
for i in range(100):
p1["value"] = i+1
root.update()
time.sleep(0.1)
root = Tk()
root.title("Progressbar组件")
# 定量进度条
p1 = ttk.Progressbar(root, length=200, mode="determinate", orient=HORIZONTAL)
p1.grid(row=1,column=1)
p1["maximum"] = 100
p1["value"] = 0
btn = ttk.Button(root,text="开始动画",command=manu_increment)
btn.grid(row=1,column=0)
root.mainloop()
Progressbar参数
-
orient :“horizontal”:水平,“vertical”:竖直
-
maximum:最大值:默认是100
-
length:长度
-
value:进度条加载数值
sbar参数** -
orient :“horizontal”:水平,“vertical”:竖直
-
maximum:最大值:默认是100
-
length:长度
-
value:进度条加载数值
-
variable:可以绑定变量