91 lines
4.1 KiB
Python
91 lines
4.1 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk, messagebox
|
|
import json
|
|
import os
|
|
|
|
CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'main_data', 'app_config.txt')
|
|
|
|
class AppSettingsWindow(tk.Tk):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.title('App Settings')
|
|
self.geometry('440x600') # Increased height for better button visibility
|
|
self.resizable(False, False)
|
|
self.config(bg='#23272e')
|
|
self.fields = {}
|
|
self.load_config()
|
|
self.style = ttk.Style(self)
|
|
self.set_styles()
|
|
self.create_widgets()
|
|
|
|
def set_styles(self):
|
|
self.style.theme_use('clam')
|
|
self.style.configure('TLabel', background='#23272e', foreground='#e0e0e0', font=('Segoe UI', 13, 'bold'))
|
|
self.style.configure('TEntry', fieldbackground='#2c313c', foreground='#e0e0e0', borderwidth=1, relief='flat', font=('Segoe UI', 12))
|
|
self.style.map('TEntry', fieldbackground=[('active', '#23272e')])
|
|
self.style.configure('TButton', background='#3b82f6', foreground='white', font=('Segoe UI', 13, 'bold'), borderwidth=0, focusthickness=3, focuscolor='#60a5fa', padding=8)
|
|
self.style.map('TButton', background=[('active', '#2563eb')])
|
|
|
|
def load_config(self):
|
|
try:
|
|
with open(CONFIG_PATH, 'r') as f:
|
|
self.config_data = json.load(f)
|
|
except Exception as e:
|
|
self.config_data = {}
|
|
messagebox.showerror('Error', f'Failed to load config: {e}')
|
|
|
|
def save_config(self):
|
|
try:
|
|
for key, entry in self.fields.items():
|
|
if hasattr(entry, 'get'):
|
|
self.config_data[key] = entry.get()
|
|
with open(CONFIG_PATH, 'w') as f:
|
|
json.dump(self.config_data, f, indent=4)
|
|
self.show_custom_popup('Success', 'Settings saved!')
|
|
except Exception as e:
|
|
messagebox.showerror('Error', f'Failed to save config: {e}')
|
|
|
|
def show_custom_popup(self, title, message):
|
|
popup = tk.Toplevel(self)
|
|
popup.title(title)
|
|
popup.geometry('320x120')
|
|
popup.configure(bg='#23272e')
|
|
popup.resizable(False, False)
|
|
popup.attributes('-topmost', True)
|
|
ttk.Label(popup, text=title, style='TLabel').pack(pady=(18, 0))
|
|
ttk.Label(popup, text=message, style='TLabel').pack(pady=(8, 0))
|
|
close_btn = ttk.Button(popup, text='OK', style='TButton', command=popup.destroy)
|
|
close_btn.pack(pady=18)
|
|
popup.grab_set()
|
|
popup.after(5000, popup.destroy)
|
|
|
|
def create_widgets(self):
|
|
title = ttk.Label(self, text='Application Settings', style='TLabel')
|
|
title.grid(row=0, column=0, columnspan=2, pady=(18, 6))
|
|
warning = tk.Label(self, text='⚠️ Modify values only if necessary or instructed!', fg='#ffb300', bg='#23272e', font=('Segoe UI', 11, 'bold'))
|
|
warning.grid(row=1, column=0, columnspan=2, pady=(0, 18))
|
|
row = 2
|
|
for key, value in self.config_data.items():
|
|
label = ttk.Label(self, text=key+':', style='TLabel')
|
|
label.grid(row=row, column=0, sticky='e', padx=18, pady=10)
|
|
if key == 'touch_screen':
|
|
var = tk.StringVar()
|
|
combo = ttk.Combobox(self, textvariable=var, values=['On', 'Off'], state='readonly', width=26)
|
|
combo.set(str(value))
|
|
combo.grid(row=row, column=1, padx=10, pady=10)
|
|
self.fields[key] = combo
|
|
else:
|
|
entry = ttk.Entry(self, style='TEntry', width=28)
|
|
entry.insert(0, str(value))
|
|
entry.grid(row=row, column=1, padx=10, pady=10)
|
|
self.fields[key] = entry
|
|
row += 1
|
|
save_btn = ttk.Button(self, text='Save Settings', style='TButton', command=self.save_config)
|
|
save_btn.grid(row=row, column=0, pady=30, sticky='e', padx=(0,10))
|
|
close_btn = ttk.Button(self, text='Close', style='TButton', command=self.destroy)
|
|
close_btn.grid(row=row, column=1, pady=30, sticky='w', padx=(10,0))
|
|
|
|
if __name__ == '__main__':
|
|
app = AppSettingsWindow()
|
|
app.mainloop()
|