-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminUserWindow.py
71 lines (59 loc) · 2.84 KB
/
AdminUserWindow.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox as msg
import sqlite3
import dblib
import addnew
import userlist
import langpack
class AdminUserWindow(tk.Toplevel):
def __init__(self, parent, selected_language):
super().__init__()
self.parent = parent
self.selected_language = selected_language
self.i18n = langpack.I18N(self.selected_language)
self.title("Admin")
self.geometry("250x210+710+290")
self.iconbitmap("python.ico")
self.db = dblib.UserDataManager()
self.create_widgets()
self.protocol("WM_DELETE_WINDOW", self.close_window)
def create_widgets(self):
self.btn_create_database = ttk.Button(self, text=self.i18n.text_create_database_button, width=30, command=self.create_db)
self.btn_fill_database = ttk.Button(self, text=self.i18n.text_fill_database_button, width=30, command=self.fill_db)
self.btn_clear_database = ttk.Button(self, text=self.i18n.text_clear_database_button, width=30, command=self.clear_db)
self.btn_add_new = ttk.Button(self, text=self.i18n.text_add_new_button_user, width=30, command=self.show_add_new_window)
self.btn_show_list = ttk.Button(self, text=self.i18n.text_show_list_button, width=30, command=self.show_user_list_window)
self.btn_create_database.pack(pady=(20, 0))
self.btn_fill_database.pack(pady=(10, 0))
self.btn_clear_database.pack(pady=(10, 0))
self.btn_add_new.pack(pady=(10, 0))
self.btn_show_list.pack(pady=(10, 0))
def create_db(self):
try:
self.db.create_database()
msg.showinfo(title="Database", message=self.i18n.message_database_create_success)
except sqlite3.Error as err:
msg.showerror(title="Database", message=self.i18n.message_database_create_error + "\n" + str(err))
def fill_db(self):
try:
self.db.fill_database()
msg.showinfo(title="Database", message=self.i18n.message_database_fill_success)
except sqlite3.Error as err:
msg.showerror(title="Database", message=self.i18n.message_database_fill_error + "\n" + str(err))
def clear_db(self):
try:
self.db.clear_database()
msg.showinfo(title="Database", message=self.i18n.message_database_clear_success)
except sqlite3.Error as err:
msg.showerror(title="Database", message=self.i18n.message_database_clear_error + "\n" + str(err))
def show_add_new_window(self):
self.withdraw()
self.add_new = addnew.AddNew(self, self.selected_language)
self.add_new.grab_set()
def show_user_list_window(self):
self.withdraw()
self.user_list = userlist.UserList(self, self.selected_language)
self.user_list.grab_set()
def close_window(self):
self.destroy()