-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
217 lines (198 loc) · 9.26 KB
/
main.py
File metadata and controls
217 lines (198 loc) · 9.26 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from settings import *
from myclass import *
def change_window(show_window: Tk, hide_window:Tk):
show_window.deiconify()
hide_window.withdraw()
if show_window == search_window:
refresh_treeview()
btn_pic.grid_forget()
connection = MyConeection()
root = Tk()
root.geometry('500x300')
root.config(bg=BG)
search_window = Toplevel(root)
management_window = Toplevel(root)
insert_window = Toplevel(management_window)
update_window = Toplevel(management_window)
delete_window = Toplevel(management_window)
search_window.withdraw()
management_window.withdraw()
insert_window.withdraw()
update_window.withdraw()
delete_window.withdraw()
search_window.config(bg=BG)
management_window.config(bg=BG)
insert_window.config(bg=BG)
update_window.config(bg=BG)
delete_window.config(bg=BG)
search_window.protocol('WM_DELETE_WINDOW', root.destroy)
management_window.protocol('WM_DELETE_WINDOW', root.destroy)
insert_window.protocol('WM_DELETE_WINDOW', root.destroy)
update_window.protocol('WM_DELETE_WINDOW', root.destroy)
delete_window.protocol('WM_DELETE_WINDOW', root.destroy)
search_window.title('Search window')
management_window.title('Management window')
insert_window.title('Insert window')
update_window.title('Update window')
delete_window.title('Delete window')
search_window.geometry('1200x800')
management_window.geometry('800x300')
insert_window.geometry('800x600')
update_window.geometry('800x600')
delete_window.geometry('800x600')
##################### management window widgets ########################
btn_insert = Button(management_window, text='Add Game', cnf=config_btn,
command=lambda:change_window(insert_window, management_window))
btn_update = Button(management_window, text='Update a Game', cnf=config_btn,
command=lambda:change_window(update_window, management_window))
btn_delete = Button(management_window, text='Delete a Game', cnf=config_btn,
command=lambda:change_window(delete_window, management_window))
btn_back_management = Button(management_window, text='Back', cnf=config_btn,
command=lambda:change_window(root, management_window))
btn_insert.pack(cnf=config_btn_root_pack)
btn_update.pack(cnf=config_btn_root_pack)
btn_delete.pack(cnf=config_btn_root_pack)
btn_back_management.pack(cnf=config_btn_root_pack)
##################### End management window widgets ########################
##################### insert window widgets ########################
game = AddGame(insert_window, connection)
btn_back_insert = Button(insert_window, text='Back', cnf=config_btn,
command=lambda:change_window(management_window, insert_window))
game.grid()
btn_back_insert.grid()
##################### End insert window widgets ########################
##################### update window widgets ########################
game_update = UpdateGame(update_window, connection)
btn_back_update = Button(update_window, text='Back', cnf=config_btn,
command=lambda:change_window(management_window, update_window))
game_update.grid(row=1, column=1, columnspan=2)
btn_back_update.grid(row=2, column=1, columnspan=2)
##################### End update window widgets ########################
##################### delete window widgets ########################
def search_delete():
name = entry_name_delete.get()
info = connection.get(name)
if info not in [(), None]:
info = f"Game: {info[1]}\nCompany: {info[2]}\nAge: {info[3]}\nPrice: {info[4]}\nConsole: {info[5]}\nStock: {info[6]}"
messagebox.showinfo("", info)
def delete_delete():
name = entry_name_delete.get()
temp = messagebox.askyesno("?", f"Delete {name}?")
if temp:
answer = connection.delete(name)
if answer == 1:
messagebox.showinfo("Success", f"Game {name} deleted successfully!")
else:
messagebox.showwarning("Warning", f"Game {name} is not in table!")
else:
messagebox.showinfo("OK", f"OK. I'll not delete {name}")
def search():
games = connection.search(e_name.get(), e_company.get(), e_age.get(), e_min_price.get(), e_max_price.get(), e_console.get(), e_min_stock.get(), e_max_stock.get())
treev.delete(*treev.get_children())
for game in games:
treev.insert("", 'end', text =game[0], values =(game[1:8]))
lable_name_delete = Label(delete_window, cnf=config_lbl, text="Which game you want to delete?")
entry_name_delete = Entry(delete_window, cnf=config_entry)
btn_search_delete_window = Button(delete_window, cnf=config_btn, text='Search',
command=search_delete)
btn_delete_delete_window = Button(delete_window, cnf=config_btn, text='Delete',
command=delete_delete)
btn_back_delete = Button(delete_window, cnf=config_btn, text='Back',
command=lambda:change_window(management_window, delete_window))
lable_name_delete.grid(row=1, column=1)
entry_name_delete.grid(row=1, column=2)
btn_search_delete_window.grid(row=2, column=1)
btn_delete_delete_window.grid(row=2, column=2)
btn_back_delete.grid(row=3, column=1, columnspan=2, sticky='ew')
##################### End delete window widgets ########################
btn_management = Button(root, text='Management', cnf=config_btn,
command=lambda:change_window(management_window, root))
btn_search = Button(root, text='Search', cnf=config_btn,
command=lambda:change_window(search_window, root))
btn_management.pack(cnf=config_btn_root_pack)
btn_search.pack(cnf=config_btn_root_pack)
def dbl_click(event):
def buy():
# ذخیره کردن اطلاعات خریدار در دیتابیس با شما
import smtplib, ssl
message = "successfully kharid shod."
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login("madval1369@gmail.com", "rwdfntxebjstxfig")
server.sendmail("madval1369@gmail.com", "mohammad.pfallah@gmail.com", message)
print('Email Sent!!!')
item = treev.selection()[0]
info = treev.item(item,"values")
aks = treev.item(item,"values")[-1]
try:
img = Image.open(aks)
img = img.resize((250, 250))
img = ImageTk.PhotoImage(img)
btn_pic.config(image=img)
btn_pic.grid(row=1, column=12)
except FileNotFoundError:
btn_pic.grid_forget()
finally:
answer = messagebox.askyesno("Buy?", f"Want to buye {info[0]}")
if answer:
buy()
btn_pic.mainloop()
treev = ttk.Treeview(search_window, selectmode ='browse')
treev.grid(row=1, column=1, columnspan=10)
treev.bind("<Double-1>", dbl_click)
verscrlbar = ttk.Scrollbar(search_window, orient ="vertical", command = treev.yview)
verscrlbar.grid(row=1, column=11, sticky='ns')
btn_pic = Button(search_window)
treev.configure(yscrollcommand = verscrlbar.set)
treev["columns"] = ("1", "2", "3" , "4" , "5" , "6" , "7")
treev['show'] = 'headings'
treev.column("1", width = 150, anchor ='c')
treev.column("2", width = 150, anchor ='c')
treev.column("3", width = 75 , anchor ='c')
treev.column("4", width = 100, anchor ='c')
treev.column("5", width = 100, anchor ='c')
treev.column("6", width = 75, anchor ='c')
treev.column("7", width = 200, anchor ='c')
treev.heading("1", text ="Name")
treev.heading("2", text ="Company")
treev.heading("3", text ="Age")
treev.heading("4", text ="price")
treev.heading("5", text ="console")
treev.heading("6", text ="stock")
treev.heading("7", text ="address")
def refresh_treeview():
treev.delete(*treev.get_children())
all_games = connection.get_all()
for game in all_games:
treev.insert("", 'end', text =game[0], values =(game[1:8]))
refresh_treeview()
search_window.bind('<Escape>', lambda e:change_window(management_window, search_window))
Label(search_window, cnf=config_lbl, text='Search by Name: ').grid(row=2, column=1)
Label(search_window, cnf=config_lbl, text='Search by Company: ').grid(row=3, column=1)
Label(search_window, cnf=config_lbl, text='Search by Age: ').grid(row=4, column=1)
Label(search_window, cnf=config_lbl, text='Search by Min Price: ').grid(row=5, column=1)
Label(search_window, cnf=config_lbl, text='Search by Max Price: ').grid(row=6, column=1)
Label(search_window, cnf=config_lbl, text='Search by Console: ').grid(row=7, column=1)
Label(search_window, cnf=config_lbl, text='Search by Min Stock: ').grid(row=8, column=1)
Label(search_window, cnf=config_lbl, text='Search by Max Stock: ').grid(row=9, column=1)
e_name = Entry(search_window, cnf=config_entry)
e_company = Entry(search_window, cnf=config_entry)
e_age = Entry(search_window, cnf=config_entry)
e_min_price = Entry(search_window, cnf=config_entry)
e_max_price = Entry(search_window, cnf=config_entry)
e_console = Entry(search_window, cnf=config_entry)
e_min_stock = Entry(search_window, cnf=config_entry)
e_max_stock = Entry(search_window, cnf=config_entry)
e_name.grid(row=2, column=2)
e_company.grid(row=3, column=2)
e_age.grid(row=4, column=2)
e_min_price.grid(row=5, column=2)
e_max_price.grid(row=6, column=2)
e_console.grid(row=7, column=2)
e_min_stock.grid(row=8, column=2)
e_max_stock.grid(row=9, column=2)
btn_search = Button(search_window, cnf=config_btn, text="Search", command=search)
btn_back_search = Button(search_window, cnf=config_btn, text="Back", command=lambda:change_window(root, search_window))
btn_search.grid(row=3, rowspan=3, sticky='news', column=3)
btn_back_search.grid(row=6, rowspan=3, sticky='news', column=3)
mainloop()