赞
踩
combobox
,notebook
,progressbar
,separator
,sizegrip
,treeview
方法
cbb = ttk.Combobox(root)
cbb['value'] = ("迪丽热巴", "古力娜扎", "马儿扎哈")
com.current(1)
示例
import tkinter as tk from tkinter import ttk root = tk.Tk() root.geometry('500x300') var = tk.StringVar() # 下拉菜单 com = ttk.Combobox(root, textvariable=var) com.pack() # 设置条目 com['value'] = ("迪丽热巴", "古力娜扎", "马儿扎哈") # 设置默认值 com.current(2) # 绑定事件 com.bind("<<ComboboxSelected>>", lambda: print(var.get())) root.mainloop()
import tkinter as tk from tkinter import ttk root = tk.Tk() root.geometry("500x300") tree = ttk.Treeview(root) tree.pack() # 添加一级树枝 tree0 = tree.insert("", 0, "中国", text="China", values=("F1")) tree1 = tree.insert("", 1, "英国", text="UK", values=("F2")) tree2 = tree.insert("", 2, "美国", text="USA", values=("F3")) # 添加二级树枝 tree00 = tree.insert(tree_1, 0, "山东", text="中国山东", values=("F1_1")) tree01 = tree.insert(tree_1, 1, "北京", text="中国北京", values=("F1_2")) tree02 = tree.insert(tree_1, 2, "江西", text="中国江西", values=("F1_3")) tree10 = tree.insert(tree_2, 0, "伦敦", text="英国伦敦", values=("F2_1")) tree11 = tree.insert(tree_2, 1, "牛津", text="英国牛津", values=("F2_2")) tree12 = tree.insert(tree_2, 2, "泰晤士", text="英国泰晤士", values=("F2_3")) tree20 = tree.insert(tree_3, 0, "华盛顿州", text="华盛顿州", values=("F3_1")) tree21 = tree.insert(tree_3, 1, "纽约州", text="纽约州", values=("F3_2")) tree22 = tree.insert(tree_3, 2, "犹他州", text="犹他州", values=("F3_3")) # 三级树枝 tree000 = tree.insert(tree_1_1, 0, "青岛", text="山东青岛", values=("F1_1_1")) tree001 = tree.insert(tree_1_1, 1, "济南", text="山东济南", values=("F1_1_2")) tree002 = tree.insert(tree_1_1, 2, "烟台", text="山东烟台", values=("F1_1_3")) root.mainloop()
import tkinter as tk from tkinter import ttk root = tk.Tk() root.geometry("500x300") tree = ttk.Treeview(root) tree.pack() # 定义列 tree['columns'] = ("姓名", '年龄', '身高', '体重') # 设置列,但此时列并不显示 tree.column('姓名', width=100) tree.column('年龄', width=100) tree.column('身高', width=100) tree.column('体重', width=100) # 设置表头 tree.heading('姓名', text='姓名-Name') tree.heading('年龄', text='年龄-Age') tree.heading('身高', text='身高-Height') tree.heading('体重', text='体重-Weight') # 添加数据 tree.insert('', 0, text="line_1", values=("迪丽热巴", "22", "178", "100")) tree.insert('', 1, text="line_2", values=("古力娜扎", "24", "160", "105")) root.mainloop()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。