Skip to content

Commit a14fc25

Browse files
Update employee_temp.py
1 parent 9e55a1a commit a14fc25

File tree

1 file changed

+82
-159
lines changed

1 file changed

+82
-159
lines changed

projects/employee_temp.py

Lines changed: 82 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -3,256 +3,179 @@
33
class EmployeeApp:
44
def __init__(self, master):
55
"""
6-
initialize the main window and configure its layout.
6+
Initialize the main window and configure its layout.
77
8-
parameters:
9-
master (Tk): the root Tkinter window instance.
8+
Parameters:
9+
master (Tk): The root Tkinter window instance.
1010
"""
11-
# initialize the main window
1211
self.master = master
13-
master.geometry("1400x750")
14-
master.resizable(0, 0) # make the window non-resizable
15-
master.title("Employee Database")
16-
master.attributes("-topmost", True) # keep the window on top
17-
18-
# configure grid layout for the master window
19-
master.columnconfigure(2, weight=1)
20-
master.rowconfigure(3, weight=1)
21-
22-
# define light grey color for borders
23-
light_grey = "#C0C0C0"
24-
25-
# create and configure frames for various sections of the form
26-
self.create_personal_info_frame(light_grey)
27-
self.create_contact_info_frame(light_grey)
28-
self.create_job_info_frame(light_grey)
29-
self.create_emergency_contact_frame(light_grey)
30-
self.create_buttons_frame(light_grey)
31-
32-
# configure grid layout for the frames to expand properly
12+
self.setup_main_window()
13+
self.create_frames()
14+
self.create_form_fields()
15+
self.create_buttons_frame("#C0C0C0")
3316
self.configure_frame_grid()
34-
35-
# adjust window size based on the content
3617
self.adjust_window_size()
37-
38-
# ====================
3918

40-
def create_personal_info_frame(self, border_color):
19+
def setup_main_window(self):
4120
"""
42-
create and place the personal information frame.
21+
Configure the main window properties.
22+
"""
23+
self.master.geometry("1400x770")
24+
self.master.resizable(False, False)
25+
self.master.title("Employee Database")
26+
self.master.attributes("-topmost", True)
27+
self.master.columnconfigure(2, weight=1)
28+
self.master.rowconfigure(3, weight=1)
4329

44-
parameters:
45-
border_color (str): the color to use for the frame's border.
30+
def create_frames(self):
31+
"""
32+
Create the frames for the various sections of the form.
4633
"""
47-
# create and place the personal information frame
34+
border_color = "#C0C0C0"
4835
self.personal_frame = self.create_frame(border_color, 0)
49-
self.create_label(self.personal_frame, "Employee Information", 0, 0, 2)
36+
self.contact_frame = self.create_frame(border_color, 1)
37+
self.job_frame = self.create_frame(border_color, 2)
38+
self.emergency_contact_frame = self.create_frame(border_color, 3)
5039

51-
# create and place personal information fields
40+
def create_form_fields(self):
41+
"""
42+
Create form fields within the respective frames.
43+
"""
44+
self.create_personal_info_frame()
45+
self.create_contact_info_frame()
46+
self.create_job_info_frame()
47+
self.create_emergency_contact_frame()
48+
49+
def create_personal_info_frame(self):
50+
"""
51+
Create and place the personal information frame.
52+
"""
53+
self.create_label(self.personal_frame, "Employee Information", 0, 0, 2)
5254
self.create_label_entry(self.personal_frame, "First Name:", 1)
5355
self.create_label_entry(self.personal_frame, "Last Name:", 2)
5456
self.create_label_entry(self.personal_frame, "Date of Birth:", 3)
5557
self.create_label_entry(self.personal_frame, "Gender:", 4)
5658

57-
# ====================
58-
59-
def create_contact_info_frame(self, border_color):
59+
def create_contact_info_frame(self):
6060
"""
61-
create and place the contact information frame.
62-
63-
parameters:
64-
border_color (str): the color to use for the frame's border.
61+
Create and place the contact information frame.
6562
"""
66-
# create and place the contact information frame
67-
self.contact_frame = self.create_frame(border_color, 1)
6863
self.create_label(self.contact_frame, "Contact Information", 0, 0, 2)
69-
70-
# create and place contact information fields
7164
self.create_label_entry(self.contact_frame, "Email Address:", 1)
7265
self.create_label_entry(self.contact_frame, "Phone Number:", 2)
7366
self.create_label_entry(self.contact_frame, "Home Address:", 3)
7467
self.create_label_entry(self.contact_frame, "Zip Code:", 4)
75-
76-
# ====================
7768

78-
def create_job_info_frame(self, border_color):
69+
def create_job_info_frame(self):
7970
"""
80-
create and place the job information frame.
81-
82-
parameters:
83-
border_color (str): the color to use for the frame's border.
71+
Create and place the job information frame.
8472
"""
85-
# create and place the job information frame
86-
self.job_frame = self.create_frame(border_color, 2)
8773
self.create_label(self.job_frame, "Job Information", 0, 0, 2)
88-
89-
# create and place job information fields
9074
self.create_label_entry(self.job_frame, "Job Title:", 1)
9175
self.create_label_entry(self.job_frame, "Department:", 2)
9276
self.create_label_entry(self.job_frame, "Hire Date:", 3)
9377
self.create_label_entry(self.job_frame, "Salary:", 4)
9478

95-
# ====================
96-
97-
def create_emergency_contact_frame(self, border_color):
79+
def create_emergency_contact_frame(self):
9880
"""
99-
create and place the emergency contact frame.
100-
101-
parameters:
102-
border_color (str): the color to use for the frame's border.
81+
Create and place the emergency contact frame.
10382
"""
104-
# create and place the emergency contact frame
105-
self.emergency_contact_frame = self.create_frame(border_color, 3)
10683
self.create_label(self.emergency_contact_frame, "Emergency Information", 0, 0, 2)
107-
108-
# create and place emergency contact fields
10984
self.create_label_entry(self.emergency_contact_frame, "First Name:", 1)
11085
self.create_label_entry(self.emergency_contact_frame, "Last Name:", 2)
11186
self.create_label_entry(self.emergency_contact_frame, "Relationship:", 3)
11287
self.create_label_entry(self.emergency_contact_frame, "Phone Number:", 4)
11388

114-
# ====================
115-
11689
def create_buttons_frame(self, border_color):
11790
"""
11891
Create and configure the buttons frame.
119-
120-
parameters:
121-
border_color (str): the color to use for the frame's border.
12292
"""
123-
# Create a frame for buttons with specified border color
12493
self.buttons_frame = Frame(self.master, relief="solid", highlightbackground=border_color, highlightthickness=1)
125-
# Place the frame in the grid at the bottom, right of the emergency_contact_frame
12694
self.buttons_frame.grid(row=3, column=1, padx=10, pady=10, sticky="nsew")
127-
# Add labels or buttons to the frame
12895
self.create_label(self.buttons_frame, "Options", 0, 0, 1)
129-
# create button within the frame
130-
self.create_button()
131-
132-
# ====================
133-
134-
def create_button(self):
96+
self.create_buttons()
97+
98+
def create_buttons(self):
13599
"""
136-
Create a button and place it in the buttons frame.
100+
Create buttons and place them in the buttons frame.
137101
"""
138-
# create button and add it to buttons frame
139-
add_button = Button(self.buttons_frame, text="Add", width=10, height=2)
140-
add_button.grid(row=1, column=0, padx=5, pady=5)
141-
142-
delete_button = Button(self.buttons_frame, text="Delete", width=10, height=2)
143-
delete_button.grid(row=2, column=0, padx=5, pady=5)
144-
145-
view_button = Button(self.buttons_frame, text="View", width=10, height=2)
146-
view_button.grid(row=1, column=1, padx=5, pady=5)
147-
148-
export_button = Button(self.buttons_frame, text="Export", width=10, height=2)
149-
export_button.grid(row=2, column=1, padx=5, pady=5)
150-
151-
# ====================
152-
102+
buttons = [("Add", 1, 0), ("Delete", 2, 0)]
103+
for (text, row, col) in buttons:
104+
button = Button(self.buttons_frame, text=text, width=10, height=2)
105+
button.grid(row=row, column=col, padx=5, pady=5)
106+
153107
def create_frame(self, border_color, row):
154108
"""
155-
create a frame with a specified border color and row placement.
109+
Create a frame with a specified border color and row placement.
156110
157-
parameters:
158-
border_color (str): the color to use for the frame's border.
159-
row (int): the row index where the frame will be placed in the grid.
111+
Parameters:
112+
border_color (str): The color to use for the frame's border.
113+
row (int): The row index where the frame will be placed in the grid.
160114
161-
returns:
162-
Frame: the created Tkinter frame.
115+
Returns:
116+
Frame: The created Tkinter frame.
163117
"""
164-
# create a frame with a specified border color and row placement
165-
frame = Frame(self.master, relief="solid", highlightbackground=border_color, highlightthickness=1, highlightcolor="#C0C0C0")
118+
frame = Frame(self.master, relief="solid", highlightbackground=border_color, highlightthickness=1, highlightcolor=border_color)
166119
frame.grid(row=row, column=0, padx=10, pady=10, sticky="nsew")
167120
return frame
168-
169-
# ====================
170121

171122
def create_label(self, parent, text, row, column, columnspan=1):
172123
"""
173-
create and place a label in a specified parent widget.
124+
Create and place a label in a specified parent widget.
174125
175-
parameters:
176-
parent (Frame): the parent widget where the label will be placed.
177-
text (str): the text to display on the label.
178-
row (int): the row index where the label will be placed in the grid.
179-
column (int): the column index where the label will be placed in the grid.
180-
columnspan (int, optional): the number of columns the label should span. default is 1.
126+
Parameters:
127+
parent (Frame): The parent widget where the label will be placed.
128+
text (str): The text to display on the label.
129+
row (int): The row index where the label will be placed in the grid.
130+
column (int): The column index where the label will be placed in the grid.
131+
columnspan (int, optional): The number of columns the label should span. Default is 1.
181132
"""
182-
# create and place a label in a specified parent widget
183133
label = Label(parent, text=text, font=("Arial", 10))
184134
label.grid(row=row, column=column, columnspan=columnspan, padx=5, pady=5, sticky="w")
185135

186-
# ====================
187-
188136
def create_label_entry(self, parent, text, row):
189137
"""
190-
create and place a label and entry widget pair.
138+
Create and place a label and entry widget pair.
191139
192-
parameters:
193-
parent (Frame): the parent widget where the label and entry will be placed.
194-
text (str): the text to display on the label.
195-
row (int): the row index where the label and entry will be placed in the grid.
140+
Parameters:
141+
parent (Frame): The parent widget where the label and entry will be placed.
142+
text (str): The text to display on the label.
143+
row (int): The row index where the label and entry will be placed in the grid.
196144
197-
returns:
198-
Entry: the created Tkinter entry widget.
145+
Returns:
146+
Entry: The created Tkinter entry widget.
199147
"""
200-
# create and place a label and entry widget pair
201148
label = Label(parent, text=text, font=("Arial", 10))
202149
label.grid(row=row, column=0, padx=5, pady=5, sticky="w")
203150
entry = Entry(parent, font=("Arial", 10))
204151
entry.grid(row=row, column=1, padx=10, pady=5, sticky="e")
205152
return entry
206153

207-
# ====================
208-
209154
def configure_frame_grid(self):
210155
"""
211-
configure grid layout for all frames to expand properly.
156+
Configure grid layout for all frames to expand properly.
212157
"""
213-
# configure grid layout for all frames to expand properly
214-
self.personal_frame.columnconfigure(1, weight=1)
215-
self.contact_frame.columnconfigure(1, weight=1)
216-
self.job_frame.columnconfigure(1, weight=1)
217-
self.emergency_contact_frame.columnconfigure(1, weight=1)
158+
frames = [self.personal_frame, self.contact_frame, self.job_frame, self.emergency_contact_frame]
159+
for frame in frames:
160+
frame.columnconfigure(1, weight=1)
218161

219-
# ====================
220-
221162
def adjust_window_size(self):
222163
"""
223-
update the window layout to calculate the total height and adjust the window size.
164+
Update the window layout to calculate the total height and adjust the window size.
224165
"""
225-
# update the window layout to calculate the total height
226166
self.master.update_idletasks()
227-
228-
# calculate the total height needed for all frames
229-
total_height = (
230-
self.personal_frame.winfo_height() +
231-
self.contact_frame.winfo_height() +
232-
self.job_frame.winfo_height() +
233-
self.emergency_contact_frame.winfo_height() +
234-
50 # additional padding between frames
235-
)
236-
237-
# set the window height to fit all frames
167+
total_height = sum(frame.winfo_height() for frame in [
168+
self.personal_frame, self.contact_frame, self.job_frame, self.emergency_contact_frame
169+
]) + 50 # Additional padding between frames
238170
self.master.geometry(f"1400x{total_height}")
239171

240-
# ====================
241-
242172
def main():
243173
"""
244-
initialize the tkinter window application.
174+
Initialize the Tkinter window application.
245175
"""
246-
# create the main window
247176
window = Tk()
248-
# create an instance of the EmployeeApp class
249177
app = EmployeeApp(window)
250-
# start the tkinter event loop
251178
window.mainloop()
252179

253-
# ====================
254-
255180
if __name__ == "__main__":
256-
# run the main function if the script is executed directly
257181
main()
258-

0 commit comments

Comments
 (0)