-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathuserinterface.py
67 lines (58 loc) · 2.03 KB
/
userinterface.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
# graphical user interface
import tkinter
from tkinter import ttk
import businesslogic as bs
import time
from ttkthemes import themed_tk as tk
from tkinter import messagebox as mb
# inserting into the database
def f():
try:
pr = bs.Product(e1.get(), e2.get(), e3.get())
output_error = pr.insert()
except IndexError:
mb.showerror("BAM", "You didn't buy anything!")
# showing what each customer bought
def g():
list_of_items = bs.Product.show()
Lb = tkinter.Listbox(master, width = 30)
for i, item in enumerate(list_of_items):
Lb.insert(i, (item[0], item[1], item[2], item[3]))
Lb.grid(row=3, column=3)
# showing the history of products that a customer bought
def purchase_history():
try:
full_name = e4.get()
purchase_hist = bs.Product.show_history(full_name.split(" "))
Lb = tkinter.Listbox(master, width = 20)
for i, item in enumerate(purchase_hist):
Lb.insert(i, (item[0], item[1]))
Lb.grid(row=3, column=18)
except IndexError:
mb.showerror("BAM", "Sorry, nothing to show!")
# setting the Adapta theme
master = tk.ThemedTk()
master.get_themes()
master.set_theme('adapta')
# Labels
ttk.Label(master, text='CustomerFirstName').grid(row=0, column=2)
ttk.Label(master, text='CustomerFamilyName').grid(row=1, column=2)
ttk.Label(master, text='ProductName').grid(row=2, column=2)
ttk.Label(master, text='Enter Customer FullName').grid(row=0, column=17)
# Inputs
e1 = ttk.Entry(master)
e2 = ttk.Entry(master)
e3 = ttk.Entry(master)
e4 = ttk.Entry(master)
e1.grid(row=0, column=3, padx=2)
e2.grid(row=1, column=3, padx=2)
e3.grid(row=2, column=3, padx=2)
e4.grid(row=0, column=18, padx=2)
# Buttons
button = ttk.Button(master, text='BUY', width=5, command=f)
button.grid(row=1, column=17)
button = ttk.Button(master, text='SHOW', width=6, command=g)
button.grid(row=2, column=17)
button = ttk.Button(master, text='PURCHASE HISTORY', width=18, command=purchase_history)
button.grid(row=1, column=18, padx=5)
tkinter.mainloop()