-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer_gui.py
58 lines (46 loc) · 1.76 KB
/
customer_gui.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
"""
GUI of the customer module
Don't forget external dependencies:
sudo apt-get install python3-tk tk-dev
See https://stackoverflow.com/questions/5459444/tkinter-python-may-not-be-configured-for-tk
"""
from tkinter import Tk, Label, Button, Entry, messagebox
from customer_database import Customer
class CustomerGUI:
"""
GUI of the customer module
"""
def __init__(self) -> None:
"""
Initialize the GUI
"""
self.customer = Customer()
self.customer.create_table()
self.window = Tk()
self.window.title("Customer")
self.window.geometry("400x200")
self.window.resizable(True, True)
self.window.configure(bg="#52e07c")
self.label_id = Label(self.window, text="ID")
self.label_id.grid(row=0, column=0, padx=10, pady=10)
self.entry_id = Entry(self.window)
self.entry_id.grid(row=0, column=1, padx=10, pady=10)
self.label_email = Label(self.window, text="Email")
self.label_email.grid(row=1, column=0, padx=10, pady=10)
self.entry_email = Entry(self.window)
self.entry_email.grid(row=1, column=1, padx=10, pady=10)
self.button_insert = Button(self.window, text="Insert", command=self.insert)
self.button_insert.grid(row=2, column=0, columnspan=2, padx=10, pady=10)
self.window.mainloop()
def insert(self) -> None:
"""
Insert a new customer in the database
"""
try:
customer_id = int(self.entry_id.get())
email = self.entry_email.get()
self.customer.insert(customer_id, email)
messagebox.showinfo("Success", "Customer inserted")
except Exception as e:
messagebox.showerror("Error", str(e))
gui = CustomerGUI()