添加深色模式

This commit is contained in:
xinzhu.yin
2026-05-28 10:50:52 +08:00
parent f8f2d471e5
commit cf724d60d7
4 changed files with 278 additions and 114 deletions

View File

@@ -45,10 +45,10 @@ def apply_modern_styles() -> None:
fg = theme.fg # 主前景
primary = theme.primary
secondary = theme.secondary
info = theme.info
dark = theme.dark
border = theme.border
inputbg = theme.inputbg
selectbg = theme.selectbg
selectfg = theme.selectfg
dark_theme = _is_dark(bg)
@@ -61,6 +61,11 @@ def apply_modern_styles() -> None:
header_hover_bg = _mix(secondary, "#ffffff", 0.08) if _is_dark(secondary) else _mix(secondary, "#000000", 0.08)
preview_fg = _mix(header_fg, header_bg, 0.35)
sidebar_bg = _mix(dark, bg, 0.18) if dark_theme else _mix(primary, "#000000", 0.10)
sidebar_hover = _mix(sidebar_bg, "#ffffff", 0.07) if dark_theme else _mix(sidebar_bg, "#000000", 0.06)
sidebar_selected = _mix(sidebar_bg, "#ffffff", 0.14) if dark_theme else _mix(sidebar_bg, "#000000", 0.10)
sidebar_fg = _mix(fg, bg, 0.05)
sidebar_muted = _mix(fg, sidebar_bg, 0.45)
# ---------------- 卡片 ----------------
style.configure(
@@ -73,20 +78,20 @@ def apply_modern_styles() -> None:
style.configure(
"CardTitle.TLabel",
background=card_bg,
foreground=primary,
font=("微软雅黑", 10, "bold"),
foreground=fg,
font=("Segoe UI", 10, "bold"),
)
style.configure(
"CardBody.TLabel",
background=card_bg,
foreground=fg,
font=("微软雅黑", 9),
font=("Segoe UI", 9),
)
style.configure(
"CardIcon.TLabel",
background=card_bg,
foreground=primary,
font=("Segoe UI Emoji", 14),
foreground=info if dark_theme else primary,
font=("Segoe UI", 9, "bold"),
)
# 内嵌于 Card 的容器(与 Card.TFrame 同背景,无边框)
@@ -107,13 +112,13 @@ def apply_modern_styles() -> None:
"ConfigHeader.TLabel",
background=header_bg,
foreground=header_fg,
font=("微软雅黑", 10, "bold"),
font=("Segoe UI", 10, "bold"),
)
style.configure(
"ConfigHeaderHover.TLabel",
background=header_hover_bg,
foreground=header_fg,
font=("微软雅黑", 10, "bold"),
font=("Segoe UI", 10, "bold"),
)
style.configure(
"ConfigChevron.TLabel",
@@ -125,7 +130,7 @@ def apply_modern_styles() -> None:
"ConfigPreview.TLabel",
background=header_bg,
foreground=preview_fg,
font=("微软雅黑", 9),
font=("Segoe UI", 9),
)
# ---------------- 顶部工具条 ----------------
@@ -133,7 +138,7 @@ def apply_modern_styles() -> None:
# 工具条上的次要按钮(清理配置等)
style.configure(
"ToolbarMuted.TButton",
font=("微软雅黑", 9),
font=("Segoe UI", 9),
padding=(10, 5),
)
@@ -142,14 +147,28 @@ def apply_modern_styles() -> None:
"SectionTitle.TLabel",
background=bg,
foreground=_mix(fg, bg, 0.45),
font=("微软雅黑", 8, "bold"),
font=("Segoe UI", 8, "bold"),
)
style.configure("Sidebar.TFrame", background=sidebar_bg, borderwidth=0)
# 侧栏内的小区段标题(侧栏背景是 primary
style.configure(
"SidebarSection.TLabel",
background=primary,
foreground=_mix("#ffffff", primary, 0.35),
font=("微软雅黑", 8, "bold"),
background=sidebar_bg,
foreground=sidebar_muted,
font=("Segoe UI", 8, "bold"),
)
# 侧栏顶部品牌区
brand_bg = _mix(sidebar_bg, "#ffffff", 0.05) if dark_theme else _mix(sidebar_bg, "#000000", 0.05)
style.configure(
"SidebarBrand.TFrame",
background=brand_bg,
borderwidth=0,
)
style.configure(
"SidebarBrand.TLabel",
background=brand_bg,
foreground="#ffffff",
font=("Segoe UI Semibold", 12),
)
# ---------------- 结果区无边框标题行 ----------------
@@ -158,7 +177,7 @@ def apply_modern_styles() -> None:
"ResultHeader.TLabel",
background=bg,
foreground=fg,
font=("微软雅黑", 11, "bold"),
font=("Segoe UI", 11, "bold"),
)
# ---------------- 状态栏 ----------------
@@ -173,47 +192,48 @@ def apply_modern_styles() -> None:
"StatusBar.TLabel",
background=statusbar_bg,
foreground=statusbar_fg,
font=("微软雅黑", 9),
font=("Segoe UI", 9),
padding=(10, 4),
)
style.configure(
"StatusBarAccent.TLabel",
background=statusbar_bg,
foreground=primary,
font=("微软雅黑", 9, "bold"),
foreground=info if dark_theme else primary,
font=("Segoe UI", 9, "bold"),
padding=(10, 4),
)
# ---------------- Sidebar 按钮(保留兼容名) ----------------
style.configure(
"Sidebar.TButton",
background=primary,
foreground="#ffffff" if _is_dark(primary) else "#1a1a1a",
font=("微软雅黑", 10),
padding=(12, 10),
background=sidebar_bg,
foreground=sidebar_fg,
font=("Segoe UI", 10),
padding=(18, 9),
borderwidth=0,
anchor="w",
)
style.map(
"Sidebar.TButton",
background=[
("active", _mix(primary, "#ffffff", 0.10)),
("pressed", _mix(primary, "#000000", 0.10)),
("active", sidebar_hover),
("pressed", sidebar_selected),
],
foreground=[("active", "#ffffff" if dark_theme else sidebar_fg)],
)
style.configure(
"SidebarSelected.TButton",
background=_mix(primary, "#000000", 0.18),
background=sidebar_selected,
foreground="#ffffff",
font=("微软雅黑", 10, "bold"),
padding=(12, 10),
font=("Segoe UI Semibold", 10),
padding=(18, 9),
borderwidth=0,
anchor="w",
)
style.map(
"SidebarSelected.TButton",
background=[
("active", _mix(primary, "#000000", 0.10)),
("pressed", _mix(primary, "#000000", 0.25)),
("active", _mix(sidebar_selected, "#ffffff", 0.06) if dark_theme else _mix(sidebar_selected, "#000000", 0.06)),
("pressed", _mix(sidebar_selected, "#000000", 0.08)),
],
)