-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress_edit.py
266 lines (213 loc) · 12 KB
/
address_edit.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
"""This module manages the UI of the Address Edit window"""
import tkinter as tk
from tkinter import messagebox as msgb
import about
import pyperclip as pc
import sqlite3 as sq
import main_window
class Address_Window():
"""This class runs the UI of the Address Window"""
def __init__(self,username, button_name,fe_name,address_1, address_2, town, district,state, pin):
"""This __init__ method is to defines the Address Window elements and strings from database"""
self.username = username
self.button_name = button_name
self.fe_name = fe_name
self.address_1 = address_1
self.address_2 = address_2
self.town = town
self.district = district
self.state = state
self.pin = pin
if (self.address_1 is None and self.address_2 is None and self.town is None and self.district is None and
self.state is None and self.pin is None) and self.fe_name == "empty":
"""This condition is to set the variables to empty is database return None"""
self.fe_name = 'empty'
self.address_1 = ''
self.address_2 = ''
self.town = ''
self.district = ''
self.state = ''
self.pin = ''
else:
pass
self.window_edit_address = tk.Toplevel()
self.window_edit_address.title('Store your address')
self.window_edit_address.geometry('475x350')
self.window_edit_address.resizable(False, False)
self.window_edit_address.configure(bg='black')
self.window_edit_address.iconbitmap('resources/icon.ico')
self.address_ui()
def entered_storage_save_button(self, event):
self.save_button.configure(bg='#a3ffb3')
def leave_storage_save_button(self, event):
self.save_button.configure(bg='#f1f5e0')
def entered_storage_clear_button(self, event):
self.clear_button.configure(bg='#a3ffb3')
def leave_storage_clear_button(self, event):
self.clear_button.configure(bg='#f1f5e0')
def entered_storage_exit_button(self, event):
self.exit_button.configure(bg='#a3ffb3')
def leave_storage_exit_button(self, event):
self.exit_button.configure(bg='#f1f5e0')
def address_ui(self):
"""This methods adds widgets to the Address Window"""
self.background = tk.PhotoImage(file='resources/line.png')
self.background_image = tk.Label(self.window_edit_address, image=self.background,
bg='black')
self.background_image.place(x=5, y=240)
self.heading = tk.Label(self.window_edit_address, text='Store your Information Safely',
font=('arial', 20, 'bold'), bg='black', fg='orange')
self.heading.pack()
self.about_image = tk.PhotoImage(file='resources/about.png')
self.about_icon = tk.Button(self.window_edit_address, image=self.about_image, bg='black', fg='white', relief='flat',
command=lambda: about.About_Window())
self.about_icon.place(x=440, y=0)
self.feature_name = tk.Label(self.window_edit_address, text='Feature Name', font=(
'arial', 12, 'bold'), bg='black', fg='white')
self.feature_name.place(x=10, y=50)
self.feature_name_entry_var = tk.StringVar()
self.feature_name_entry = tk.Entry(self.window_edit_address, textvariable=self.feature_name_entry_var, font=(
'arial', 12), bg='#C0C0C0', width=20)
self.feature_name_entry.place(x=130, y=50)
self.feature_name_entry_var.set(self.fe_name)
self.feature_name_entry.focus()
self.note_for_feature_name = tk.Label(self.window_edit_address,
text='Note: Feature name is displayed on the button in the Main window', font=(
'arial', 10), bg='black', fg='orange')
self.note_for_feature_name.place(x=2, y=75)
self.address_line_1 = tk.Label(self.window_edit_address, text='Address Line 1', font=(
'arial', 12, 'bold'), bg='black', fg='white')
self.address_line_1.place(x=5, y=100)
self.address_line_1_entry_var = tk.StringVar()
self.address_line_1_entry = tk.Entry(self.window_edit_address, textvariable=self.address_line_1_entry_var,
font=('arial', 12), bg='#C0C0C0', width=30)
self.address_line_1_entry.place(x=130, y=100)
self.address_line_1_entry_var.set(self.address_1)
self.data_add_1 = self.address_line_1_entry_var.get()
self.copy_image = tk.PhotoImage(file='resources/copy.png')
self.copy_add_1 = tk.Button(self.window_edit_address, image=self.copy_image, relief='groove',
command=lambda: self.copy_data(self.data_add_1))
self.copy_add_1.place(x=410, y=100)
self.address_line_2 = tk.Label(self.window_edit_address, text='Address Line 2', font=(
'arial', 12, 'bold'), bg='black', fg='white')
self.address_line_2.place(x=5, y=125)
self.address_line_2_entry_var = tk.StringVar()
self.address_line_2_entry = tk.Entry(self.window_edit_address, textvariable=self.address_line_2_entry_var,
font=('arial', 12), bg='#C0C0C0', width=30)
self.address_line_2_entry.place(x=130, y=125)
self.address_line_2_entry_var.set(self.address_2)
self.data_add_2 = self.address_line_2_entry_var.get()
self.copy_add_2 = tk.Button(self.window_edit_address, image=self.copy_image, relief='groove',
command=lambda: self.copy_data(self.data_add_2))
self.copy_add_2.place(x=410, y=125)
self.town_label = tk.Label(self.window_edit_address, text='Town/City', font=(
'arial', 12, 'bold'), bg='black', fg='white')
self.town_label.place(x=40, y=150)
self.town_entry_var = tk.StringVar()
self.town_entry = tk.Entry(self.window_edit_address, textvariable=self.town_entry_var, font=(
'arial', 12), bg='#C0C0C0', width=20)
self.town_entry.place(x=130, y=150)
self.town_entry_var.set(self.town)
self.town_data = self.town_entry_var.get()
self.copy_town = tk.Button(self.window_edit_address, image=self.copy_image, relief='groove',
command=lambda: self.copy_data(self.town_data))
self.copy_town.place(x=320, y=150)
self.district_label = tk.Label(self.window_edit_address, text='District', font=(
'arial', 12, 'bold'), bg='black', fg='white')
self.district_label.place(x=60, y=175)
self.district_entry_var = tk.StringVar()
self.district_entry = tk.Entry(self.window_edit_address, textvariable=self.district_entry_var,
font=('arial', 12), bg='#C0C0C0', width=20)
self.district_entry.place(x=130, y=175)
self.district_entry_var.set(self.district)
self.data_district = self.district_entry_var.get()
self.copy_district = tk.Button(self.window_edit_address, image=self.copy_image, relief='groove',
command=lambda: self.copy_data(self.data_district))
self.copy_district.place(x=320, y=175)
self.state_label = tk.Label(self.window_edit_address, text='State', font=(
'arial', 12, 'bold'), bg='black', fg='white')
self.state_label.place(x=75, y=200)
self.state_entry_var = tk.StringVar()
self.state_entry = tk.Entry(self.window_edit_address, textvariable=self.state_entry_var,
font=('arial', 12), bg='#C0C0C0', width=20)
self.state_entry.place(x=130, y=200)
self.state_entry_var.set(self.state)
self.data_state = self.state_entry_var.get()
self.copy_state = tk.Button(self.window_edit_address, image=self.copy_image, relief='groove',
command=lambda: self.copy_data(self.data_state))
self.copy_state.place(x=320, y=200)
self.pin_label = tk.Label(self.window_edit_address, text='Pin Code', font=(
'arial', 12, 'bold'), bg='black', fg='white')
self.pin_label.place(x=45, y=225)
self.pin_code_entry_var = tk.StringVar()
self.pin_code_entry = tk.Entry(self.window_edit_address, textvariable=self.pin_code_entry_var,
font=('arial', 12), bg='#C0C0C0', width=20)
self.pin_code_entry.place(x=130, y=225)
self.pin_code_entry_var.set(self.pin)
self.data_pin = self.pin_code_entry_var.get()
self.copy_pin = tk.Button(self.window_edit_address, image=self.copy_image, relief='groove',
command=lambda: self.copy_data(self.data_pin))
self.copy_pin.place(x=320, y=225)
self.save_button = tk.Button(self.window_edit_address, text='Save', font=(
'consolas', 13, 'bold'), relief='groove', width=8, bg='#f1f5e0',
command=self.get_data)
self.save_button.place(x=30, y=300)
self.save_button.bind('<Enter>', self.entered_storage_save_button)
self.save_button.bind('<Leave>', self.leave_storage_save_button)
self.clear_button = tk.Button(self.window_edit_address, text='Clear', font=(
'consolas', 13, 'bold'), relief='groove', width=8, bg='#f1f5e0', command=self.clear)
self.clear_button.place(x=180, y=300)
self.clear_button.bind('<Enter>', self.entered_storage_clear_button)
self.clear_button.bind('<Leave>', self.leave_storage_clear_button)
self.exit_button = tk.Button(self.window_edit_address, text='Exit', font=(
'consolas', 13, 'bold'), relief='groove', width=8, bg='#f1f5e0', command=self.exit_window)
self.exit_button.place(x=330, y=300)
self.exit_button.bind('<Enter>', self.entered_storage_exit_button)
self.exit_button.bind('<Leave>', self.leave_storage_exit_button)
self.window_edit_address.focus_force()
self.window_edit_address.mainloop()
def get_data(self):
"""This method collects the data to update the database"""
fe_name = self.feature_name_entry_var.get()
add_1 = self.address_line_1_entry_var.get()
add_2 = self.address_line_2_entry_var.get()
town_var = self.town_entry_var.get()
district_var = self.district_entry_var.get()
state_var = self.state_entry_var.get()
pin_var = self.pin_code_entry_var.get()
self.update_address_data(fe_name, add_1, add_2, town_var, district_var, state_var,pin_var)
def update_address_data(self, fe_name, add_1, add_2, town, district, state, pin):
"""This method updates the data in the address table in database"""
conn = sq.connect('database.db')
cursor = conn.cursor()
update = f"""UPDATE {self.username}_address set fe_name = "{fe_name}",
line_1 = "{add_1}",
line_2 = "{add_2}" ,
city = "{town}",
district = "{district}",
state = "{state}",
pin_code = "{pin}"
WHERE val_no = "{self.button_name}" """
cursor.execute(update)
msgb.showinfo('Success', 'You have successfully updated the data')
conn.commit()
conn.close()
main_window.object.change_the_address_box_name(self.username)
self.window_edit_address.destroy()
@staticmethod
def copy_data(text):
"""This method copies the selected data to the clipboard"""
pc.copy(text)
def exit_window(self):
"""This method exits Address Window"""
self.window_edit_address.destroy()
def clear(self):
""" Clears all the input in the window"""
self.feature_name_entry_var.set('empty')
self.address_line_1_entry_var.set('')
self.address_line_2_entry_var.set('')
self.town_entry_var.set('')
self.district_entry_var.set('')
self.state_entry_var.set('')
self.pin_code_entry_var.set('')
self.feature_name_entry.focus()