forked from LBEILC/JCZX_AssetTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings_tab.py
48 lines (41 loc) · 1.46 KB
/
settings_tab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# settings_tab.py
import tkinter as tk
from tkinter import ttk
import json
CONFIG_FILE = 'app_config.json'
def load_config():
default_config = {
'theme': 'minty',
'decrypt_path': '',
'encrypt_path': '',
'cache_file': ''
}
try:
with open(CONFIG_FILE, 'r') as f:
config = json.load(f)
return {**default_config, **config}
except FileNotFoundError:
return default_config
def save_config(config):
with open(CONFIG_FILE, 'w') as f:
json.dump(config, f)
class SettingsTab:
def __init__(self, parent, style):
self.parent = parent
self.style = style
self.config = load_config()
self.create_widgets()
def create_widgets(self):
# 主题选择下拉框
self.theme_label = ttk.Label(self.parent, text="主题:")
self.theme_label.pack(side=tk.TOP, fill=tk.X, padx=5, pady=5)
self.theme_combobox = ttk.Combobox(self.parent, values=self.style.theme_names(), state='readonly')
self.theme_combobox.set(self.config.get('theme', 'default'))
self.theme_combobox.pack(side=tk.TOP, fill=tk.X, padx=5, pady=5)
self.theme_combobox.bind('<<ComboboxSelected>>', self.change_theme)
# 其他设置控件可以继续添加
def change_theme(self, event):
new_theme = self.theme_combobox.get()
self.style.theme_use(new_theme)
self.config['theme'] = new_theme
save_config(self.config)