tkinter_ttk_clam主题

如下

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
# root.geometry("550x600+5+5")
root.configure(bg="#dcdad5")
root.title("clam")

s=ttk.Style()
# print(s.theme_names())
s.theme_use('clam')

ctnvar1 = tk.IntVar(value=1)
ctnvar2 = tk.IntVar(value=0)
rtnvar1 = tk.IntVar(value=0)
rtnvar2 = tk.IntVar(value=0)

frame1 = tk.LabelFrame(root,text="标签1",bg="#dcdad5",bd=1,relief="solid")
frame1.pack(side="top",anchor="nw",pady=0,padx=5,fill="x")

label1 = tk.Label(frame1,text="这是一个标签",bg="gray")
label1.pack(side="left",padx=(5,0),pady=(0,5))
btn1 = ttk.Button(frame1,text="这是一个按钮",takefocus=0)
btn1.pack(side="left",padx=(5,0),pady=(0,5))

ctn1 = ttk.Checkbutton(frame1,text="这是一个按钮1",takefocus=0,variable=ctnvar1)
ctn1.pack(side="left",padx=(5,0),pady=(0,5))
ctn2 = ttk.Checkbutton(frame1,text="这是一个按钮2",takefocus=0,variable=ctnvar2)
ctn2.pack(side="left",padx=(5,5),pady=(0,5))

rtn1 = ttk.Radiobutton(frame1,text="按钮3",takefocus=0,value=1,variable=rtnvar1)
rtn1.pack(side="left",padx=(5,0),pady=(0,5))
rtn2 = ttk.Radiobutton(frame1,text="按钮4",takefocus=0,value=0,variable=rtnvar1)
rtn2.pack(side="left",padx=5,pady=(0,5))



frame2 = tk.LabelFrame(root,text="标签2",bg="#dcdad5",bd=1,relief="solid")
frame2.pack(side="top",anchor="nw",pady=0,padx=5,fill="x")

scrollbar1 = ttk.Scrollbar(frame2)
scrollbar1.pack(side="right",pady=(0,5),padx=(0,5),fill="y")

text1 = tk.Text(frame2,height=5,bd=0,relief="solid",yscrollcommand=scrollbar1.set)
text1.pack(side="left",pady=(0,5),padx=(5,0),fill="both")
scrollbar1.configure(command=text1.yview)

frame3 = tk.LabelFrame(root,text="标签3",bg="#dcdad5",bd=1,relief="solid")
frame3.pack(side="top",anchor="nw",pady=(0,5),padx=5,fill="x")

tabw = ttk.Notebook(frame3,takefocus=1)
tabw.pack(side="top",anchor="nw",pady=(0,5),padx=5)

tab1 = ttk.Frame(tabw,takefocus=1)
tabw.add(tab1,text='Tab 1')
tab2 = ttk.Frame(tabw,takefocus=1)
tabw.add(tab2,text='Tab 2')

ent1 = tk.Entry(tab1,bd=0,relief="solid")
ent1.pack(side="top",anchor="nw",padx=5,pady=5)

spb1 = ttk.Spinbox(tab1,from_=3,to=9)
spb1.pack(side="top",anchor="nw",padx=5,pady=(0,5))

vlist = ["Option1","Option2","Option3","Option4","Option5"]

combobox1 = ttk.Combobox(tab1,values=vlist)
combobox1.pack(side="top",anchor="nw",pady=5,padx=5)

s.configure('1.TSeparator',background='gray94')
sep1 = ttk.Separator(tab1,orient='horizontal',style='1.TSeparator')
sep1.pack(fill='x',pady=2,padx=5)

scale1 = tk.Scale(tab1,from_=5,to=11,orient="horizontal",
         length=200,showvalue=1,tickinterval=3,resolution=0.01,
         activebackground="blue",
         sliderrelief="flat",borderwidth=0,state="active",
         highlightbackground="black",highlightcolor="black",
         highlightthickness=0,bg="#dcdad5",sliderlength=20,width=10)
scale1.pack(side="top",anchor="nw",pady=(0,5),padx=5)

probar1 = ttk.Progressbar(tab1,mode='indeterminate',length=200)
probar1.pack(side="top",anchor="nw",pady=(0,5),padx=5)
probar1.start(20)


# 定义列的名称
columns = ("name", "gender", "age")
tree = ttk.Treeview(tab2, show = "headings", columns = columns,
                    selectmode = tk.BROWSE,height=5)
                    
# 设置表格文字居中
tree.column("name", anchor = "center",width=100)
tree.column("gender", anchor = "center",width=100)
tree.column("age", anchor = "center",width=100)
# 设置表格头部标题
tree.heading("name", text = "姓名")
tree.heading("gender", text = "性别")
tree.heading("age", text = "年龄")
# 设置表格内容
lists = [{"name": "杨铁蓝", "gender": "男", "age": "18"}, 
         {"name": "郑和", "gender": "女", "age": "71"},
         {"name": "李宗盛", "gender": "男", "age": "45"},
         {"name": "武当王", "gender": "女", "age": "125"}]
i = 0
for v in lists:
    tree.insert('', i, values = (v.get("name"), v.get("gender"), v.get("age")))
    i += 1

tree.pack(side="left",anchor="nw",pady=5,padx=5)
# 获取当前点击行的值
def treeviewClick(event):  # 单击
    for item in tree.selection():
        item_text = tree.item(item, "values")
        print(item_text)
# 鼠标左键抬起
tree.bind('<ButtonRelease-1>', treeviewClick)

root.mainloop()

如图:

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页