import sys import ctypes from tkinter import ttk _PALETTES = { "dark": { "BG": "#111519", "SURFACE": "#1A2026", "SURFACE_LIGHT": "#232B33", "SURFACE_HOVER": "#2D3741", "ENTRY_BG": "#13181C", "BORDER": "#313C47", "BORDER_FOCUS": "#6BC5B8", "ACCENT": "#3E9B8F", "ACCENT_LIGHT": "#8CE0D4", "ACCENT_HOVER": "#338378", "ACCENT_MUTED": "#192B2B", "ACCENT_GRADIENT": "#5CC0B3", "TEXT": "#ECF1F5", "SUBTEXT": "#9AA6B2", "MUTED": "#64707D", "SUCCESS": "#38C998", "SUCCESS_HOVER": "#2BA87D", "WARNING": "#F0A830", "ERROR": "#F05454", "DANGER_HOVER": "#D43F3F", "TAB_BG": "#161B20", "TAB_ACTIVE": "#1B2E2F", "TAB_HOVER": "#20272F", }, "light": { "BG": "#E8EDF2", "SURFACE": "#F8FAFC", "SURFACE_LIGHT": "#E1E7EE", "SURFACE_HOVER": "#D3DCE6", "ENTRY_BG": "#FFFFFF", "BORDER": "#C5CFD9", "BORDER_FOCUS": "#2E857A", "ACCENT": "#2E857A", "ACCENT_LIGHT": "#1E665D", "ACCENT_HOVER": "#236B62", "ACCENT_MUTED": "#DDF2EE", "ACCENT_GRADIENT": "#3E9B8F", "TEXT": "#161C22", "SUBTEXT": "#4F5B67", "MUTED": "#7E8B98", "SUCCESS": "#159E72", "SUCCESS_HOVER": "#0E805B", "WARNING": "#C97A10", "ERROR": "#DC3838", "DANGER_HOVER": "#B82828", "TAB_BG": "#F3F6F9", "TAB_ACTIVE": "#DDF2EE", "TAB_HOVER": "#E8EEF3", }, } _PALETTE_NAMES = tuple(_PALETTES["dark"]) for _name, _value in _PALETTES["dark"].items(): globals()[_name] = _value FONT_HERO = ("Segoe UI", 20, "bold") FONT_TITLE = ("Segoe UI", 14, "bold") FONT_SUBTITLE = ("Segoe UI", 11, "bold") FONT_REGULAR = ("Segoe UI", 10) FONT_BOLD = ("Segoe UI", 10, "bold") FONT_SMALL = ("Segoe UI", 9) FONT_SMALL_BOLD = ("Segoe UI", 9, "bold") FONT_STAT = ("Segoe UI", 11, "bold") FONT_MONO = ("Consolas", 9) def apply_windows_titlebar(root, is_dark=True): """Windows 10/11 pencere başlık çubuğunu karanlık/aydınlık temaya uyarlar.""" if sys.platform != "win32": return try: root.update_idletasks() hwnd = ctypes.windll.user32.GetParent(root.winfo_id()) value = ctypes.c_int(1 if is_dark else 0) # DWMWA_USE_IMMERSIVE_DARK_MODE = 20 (Windows 11 & Win10 20H1+), 19 (Win10 1809-1909) hr = ctypes.windll.dwmapi.DwmSetWindowAttribute( hwnd, 20, ctypes.byref(value), ctypes.sizeof(value) ) if hr != 0: ctypes.windll.dwmapi.DwmSetWindowAttribute( hwnd, 19, ctypes.byref(value), ctypes.sizeof(value) ) except Exception: pass def apply_theme(root, mode="dark"): """Apply a palette to custom Tk widgets and native ttk controls.""" if mode not in _PALETTES: mode = "dark" palette = _PALETTES[mode] globals().update(palette) for module_name, module in tuple(sys.modules.items()): if module_name == "ui" or module_name.startswith("ui."): namespace = getattr(module, "__dict__", {}) for name, value in palette.items(): if name in namespace: namespace[name] = value root.configure(bg=palette["BG"]) apply_windows_titlebar(root, is_dark=(mode == "dark")) style = ttk.Style(root) style.theme_use("clam") style.configure("TFrame", background=BG) style.configure("TLabel", background=BG, foreground=TEXT, font=FONT_REGULAR) style.configure( "Custom.Horizontal.TProgressbar", troughcolor=SURFACE_LIGHT, background=ACCENT, lightcolor=ACCENT_GRADIENT, darkcolor=ACCENT, bordercolor=SURFACE_LIGHT, thickness=10, borderwidth=0, ) style.configure( "Vertical.TScrollbar", background=SURFACE_LIGHT, troughcolor=BG, arrowcolor=SUBTEXT, borderwidth=0, relief="flat", width=10, ) style.map( "Vertical.TScrollbar", background=[("active", SURFACE_HOVER), ("pressed", ACCENT)], ) style.configure( "TCombobox", fieldbackground=ENTRY_BG, background=SURFACE_LIGHT, foreground=TEXT, bordercolor=BORDER, lightcolor=BORDER, darkcolor=BORDER, arrowcolor=ACCENT_LIGHT, padding=(10, 7), relief="flat", ) style.map( "TCombobox", fieldbackground=[("readonly", ENTRY_BG), ("disabled", SURFACE_LIGHT)], foreground=[("readonly", TEXT), ("disabled", MUTED)], selectbackground=[("readonly", ENTRY_BG)], selectforeground=[("readonly", TEXT)], bordercolor=[("focus", BORDER_FOCUS)], ) root.option_add("*TCombobox*Listbox.background", SURFACE) root.option_add("*TCombobox*Listbox.foreground", TEXT) root.option_add("*TCombobox*Listbox.selectBackground", ACCENT_MUTED) root.option_add("*TCombobox*Listbox.selectForeground", ACCENT_LIGHT) root.option_add("*TCombobox*Listbox.font", FONT_REGULAR) style.configure( "Treeview", background=SURFACE, foreground=TEXT, fieldbackground=SURFACE, bordercolor=BORDER, borderwidth=0, font=FONT_REGULAR, rowheight=40, ) style.configure( "Treeview.Heading", background=SURFACE_LIGHT, foreground=SUBTEXT, borderwidth=0, font=FONT_SMALL_BOLD, padding=(12, 10), relief="flat", ) style.map( "Treeview.Heading", background=[("active", SURFACE_HOVER)], foreground=[("active", TEXT)], ) style.map( "Treeview", background=[("selected", ACCENT_MUTED)], foreground=[("selected", ACCENT_LIGHT)], )