-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings_menu.py
48 lines (30 loc) · 1.28 KB
/
settings_menu.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
import os
import json
import customtkinter as ctk
class SettingsMenu(ctk.CTkToplevel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.geometry('300x400')
self.title('Settings')
self.settings = self.load_settings()
ctk.set_appearance_mode(self.settings['theme'])
self.label1 = ctk.CTkLabel(self, text = 'Color Theme').pack(pady = (10, 2))
self.combobox1 = ctk.CTkComboBox(
self,
values = ['system', 'dark', 'light'],
variable = ctk.StringVar(value = self.settings['theme']),
command = lambda choice: self.set_theme(choice)
).pack()
def load_settings(self) -> dict:
if not os.path.exists('./config/settings.json'):
with open('./config/settings.json', 'w') as file:
json.dump({'theme': 'system'}, file)
with open('./config/settings.json') as file:
return json.load(file)
def write_settings(self, settings: dict) -> None:
with open('./config/settings.json', 'w') as file:
json.dump(settings, file)
def set_theme(self, theme):
self.settings['theme'] = theme
ctk.set_appearance_mode(theme)
self.write_settings(self.settings)