赞
踩
ttkbootstrap 附带了许多风格精美的浅色和深色主题,您可以在 安装 ttkbootstrap 后 在终端中键入此命令,在演示中查看这些主题。
python -m ttkbootstrap
将看到如下图所示的演示屏幕。 在 Select a theme 下拉框中更改主题选择,演示屏幕将更新为新主题。
标准主题在 ttkbootstrap.themes.standard
模块中定义。
{
"cosmo": {
"type": "light",
"colors": {
"primary": "#2780e3",
"secondary": "#7E8081",
"success": "#3fb618",
"info": "#9954bb",
"warning": "#ff7518",
"danger": "#ff0039",
"light": "#F8F9FA",
"dark": "#373A3C",
"bg": "#ffffff",
"fg": "#373a3c",
"selectbg": "#7e8081",
"selectfg": "#ffffff",
"border": "#ced4da",
"inputfg": "#373a3c",
"inputbg": "#fdfdfe",
},
},
"flatly": {
"type": "light",
"colors": {
"primary": "#2c3e50",
"secondary": "#95a5a6",
"success": "#18bc9c",
"info": "#3498db",
"warning": "#f39c12",
"danger": "#e74c3c",
"light": "#ECF0F1",
"dark": "#7B8A8B",
"bg": "#ffffff",
"fg": "#212529",
"selectbg": "#95a5a6",
"selectfg": "#ffffff",
"border": "#ced4da",
"inputfg": "#212529",
"inputbg": "#ffffff",
},
},
"litera": {
"type": "light",
"colors": {
"primary": "#4582ec",
"secondary": "#adb5bd",
"success": "#02b875",
"info": "#17a2b8",
"warning": "#f0ad4e",
"danger": "#d9534f",
"light": "#F8F9FA",
"dark": "#343A40",
"bg": "#ffffff",
"fg": "#343a40",
"selectbg": "#adb5bd",
"selectfg": "#ffffff",
"border": "#bfbfbf",
"inputfg": "#343a40",
"inputbg": "#fff",
},
},
"minty": {
"type": "light",
"colors": {
"primary": "#78c2ad",
"secondary": "#f3969a",
"success": "#56cc9d",
"info": "#6cc3d5",
"warning": "#ffce67",
"danger": "#ff7851",
"light": "#F8F9FA",
"dark": "#343A40",
"bg": "#ffffff",
"fg": "#5a5a5a",
"selectbg": "#f3969a",
"selectfg": "#ffffff",
"border": "#ced4da",
"inputfg": "#696969",
"inputbg": "#fff",
},
},
"lumen": {
"type": "light",
"colors": {
"primary": "#158cba",
"secondary": "#919191",
"success": "#28b62c",
"info": "#75caeb",
"warning": "#ff851b",
"danger": "#ff4136",
"light": "#F6F6F6",
"dark": "#555555",
"bg": "#ffffff",
"fg": "#555555",
"selectbg": "#919191",
"selectfg": "#ffffff",
"border": "#ced4da",
"inputfg": "#555555",
"inputbg": "#fff",
},
},
"sandstone": {
"type": "light",
"colors": {
"primary": "#325D88",
"secondary": "#8e8c84",
"success": "#93c54b",
"info": "#29abe0",
"warning": "#f47c3c",
"danger": "#d9534f",
"light": "#F8F5F0",
"dark": "#3E3F3A",
"bg": "#ffffff",
"fg": "#3e3f3a",
"selectbg": "#8e8c84",
"selectfg": "#ffffff",
"border": "#ced4da",
"inputfg": "#6E6D69",
"inputbg": "#fff",
},
},
"yeti": {
"type": "light",
"colors": {
"primary": "#008cba",
"secondary": "#707070",
"success": "#43ac6a",
"info": "#5bc0de",
"warning": "#e99002",
"danger": "#f04124",
"light": "#EEEEEE",
"dark": "#222222",
"bg": "#ffffff",
"fg": "#222222",
"selectbg": "#707070",
"selectfg": "#ffffff",
"border": "#cccccc",
"inputfg": "#222222",
"inputbg": "#fff",
},
},
"pulse": {
"type": "light",
"colors": {
"primary": "#593196",
"secondary": "#69676E",
"success": "#13b955",
"info": "#009cdc",
"warning": "#efa31d",
"danger": "#fc3939",
"light": "#F9F8FC",
"dark": "#17141F",
"bg": "#ffffff",
"fg": "#444444",
"selectbg": "#69676e",
"selectfg": "#ffffff",
"border": "#cbc8d0",
"inputfg": "#444444",
"inputbg": "#fdfdfe",
},
},
"united": {
"type": "light",
"colors": {
"primary": "#e95420",
"secondary": "#aea79f",
"success": "#38b44a",
"info": "#17a2b8",
"warning": "#efb73e",
"danger": "#df382c",
"light": "#E9ECEF",
"dark": "#772953",
"bg": "#ffffff",
"fg": "#333333",
"selectbg": "#aea79f",
"selectfg": "#ffffff",
"border": "#ced4da",
"inputfg": "#333333",
"inputbg": "#fff",
},
},
"morph": {
"type": "light",
"colors": {
"primary": "#378DFC",
"secondary": "#aaaaaa",
"success": "#43cc29",
"info": "#5B62F4",
"warning": "#FFC107",
"danger": "#E52527",
"light": "#F0F5FA",
"dark": "#212529",
"bg": "#D9E3F1",
"fg": "#7B8AB8",
"selectbg": "#aaaaaa",
"selectfg": "#FBFDFF",
"border": "#B9C7DA",
"inputfg": "#7F8EBA",
"inputbg": "#F0F5FA",
},
},
"journal": {
"type": "light",
"colors": {
"primary": "#eb6864",
"secondary": "#aaaaaa",
"success": "#22b24c",
"info": "#336699",
"warning": "#f5e625",
"danger": "#f57a00",
"light": "#F8F9FA",
"dark": "#222222",
"bg": "#ffffff",
"fg": "#222222",
"selectbg": "#aaaaaa",
"selectfg": "#ffffff",
"border": "#ced4da",
"inputfg": "#565656",
"inputbg": "#fff",
},
},
"darkly": {
"type": "dark",
"colors": {
"primary": "#375a7f",
"secondary": "#444444",
"success": "#00bc8c",
"info": "#3498db",
"warning": "#f39c12",
"danger": "#e74c3c",
"light": "#ADB5BD",
"dark": "#303030",
"bg": "#222222",
"fg": "#ffffff",
"selectbg": "#555555",
"selectfg": "#ffffff",
"border": "#222222",
"inputfg": "#ffffff",
"inputbg": "#2f2f2f",
},
},
"superhero": {
"type": "dark",
"colors": {
"primary": "#4c9be8",
"secondary": "#4e5d6c",
"success": "#5cb85c",
"info": "#5bc0de",
"warning": "#f0ad4e",
"danger": "#d9534f",
"light": "#ABB6C2",
"dark": "#20374C",
"bg": "#2b3e50",
"fg": "#ffffff",
"selectbg": "#526170",
"selectfg": "#ffffff",
"border": "#222222",
"inputfg": "#ebebeb",
"inputbg": "#32465a",
},
},
"solar": {
"type": "dark",
"colors": {
"primary": "#bc951a",
"secondary": "#94a2a4",
"success": "#44aca4",
"info": "#3f98d7",
"warning": "#d05e2f",
"danger": "#d95092",
"light": "#A9BDBD",
"dark": "#073642",
"bg": "#002B36",
"fg": "#ffffff",
"selectbg": "#0b5162",
"selectfg": "#ffffff",
"border": "#00252e",
"inputfg": "#A9BDBD",
"inputbg": "#073642",
},
},
"cyborg": {
"type": "dark",
"colors": {
"primary": "#2a9fd6",
"secondary": "#555555",
"success": "#77b300",
"info": "#9933cc",
"warning": "#ff8800",
"danger": "#cc0000",
"light": "#ADAFAE",
"dark": "#222222",
"bg": "#060606",
"fg": "#ffffff",
"selectbg": "#454545",
"selectfg": "#ffffff",
"border": "#060606",
"inputfg": "#ffffff",
"inputbg": "#191919",
},
},
"vapor": {
"type": "dark",
"colors": {
"primary": "#6e40c0",
"secondary": "#ea38b8",
"success": "#3af180",
"info": "#1da2f2",
"warning": "#ffbd05",
"danger": "#e34b54",
"light": "#44d7e8",
"dark": "#170229",
"bg": "#190831",
"fg": "#32fbe2",
"selectbg": "#461a8a",
"selectfg": "#ffffff",
"border": "#060606",
"inputfg": "#bfb6cd",
"inputbg": "#30115e",
},
},
"simplex": {
"type": "light",
"colors": {
"primary": "#d8220e",
"secondary": "#858e96",
"success": "#469307",
"info": "#0099ce",
"warning": "#d88220",
"danger": "#9a479e",
"light": "#f2f2f2",
"dark": "#3b3d3f",
"bg": "#fcfcfc",
"fg": "#3b3d3f",
"selectbg": "#a9afb6",
"selectfg": "#ffffff",
"border": "#858e96",
"inputfg": "#3b3d3f",
"inputbg": "#fcfcfc",
},
},
"cerculean": {
"type": "light",
"colors": {
"primary": "#4bb1ea",
"secondary": "#a9b4be",
"success": "#84b251",
"info": "#225384",
"warning": "#e16e25",
"danger": "#cf3c40",
"light": "#eceef1",
"dark": "#33383e",
"bg": "#ffffff",
"fg": "#2ea4e7",
"selectbg": "#adb5bd",
"selectfg": "#ffffff",
"border": "#a9b4be",
"inputfg": "#495057",
"inputbg": "#ffffff",
},
},
}
通过 ttk.Style().theme_use(theme_value)进行设置
ttk.Style().theme_names() 以列表的形式返回多个主题名
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
root = ttk.Window()
style = ttk.Style()
theme_names = style.theme_names() # 以列表的形式返回多个主题名
theme_selection = ttk.Frame(root, padding=(10, 10, 10, 0))
theme_selection.pack(fill=X, expand=YES)
lbl = ttk.Label(theme_selection, text="选择主题:")
theme_cbo = ttk.Combobox(
master=theme_selection,
text=style.theme.name,
values=theme_names,
)
theme_cbo.pack(padx=10, side=RIGHT)
theme_cbo.current(theme_names.index(style.theme.name))
lbl.pack(side=RIGHT)
def change_theme(event):
theme_cbo_value = theme_cbo.get()
style.theme_use(theme_cbo_value)
theme_selected.configure(text=theme_cbo_value)
theme_cbo.selection_clear()
theme_cbo.bind('<<ComboboxSelected>>', change_theme)
theme_selected = ttk.Label(
master=theme_selection,
text="litera",
font="-size 24 -weight bold"
)
theme_selected.pack(side=LEFT)
root.mainloop()
TTK创建器 与 ttkbootstrap 打包,以便可以修改、保存、导出和导入创建的主题。
要运行该程序,您安装ttkbootstrap
后 在控制台中键入以下命令:
python -m ttkcreator
所有用于更改主题的控件都在左侧控制框架上。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。