11from tkinter import *
2- from tkinter import messagebox
32
43class EmployeeApp :
54 def __init__ (self , master ):
6- # Initialize the main window
5+ """
6+ initialize the main window and configure its layout.
7+
8+ parameters:
9+ master (Tk): the root Tkinter window instance.
10+ """
11+ # initialize the main window
712 self .master = master
8- master .geometry ("1400x800" )
9- # make the window non-resizable
10- master .resizable (0 , 0 )
11- # set the title of the window
13+ master .geometry ("1400x750" )
14+ master .resizable (0 , 0 ) # make the window non-resizable
1215 master .title ("Employee Database" )
13- # keep the window on top
14- master .attributes ("-topmost" , True )
16+ master .attributes ("-topmost" , True ) # keep the window on top
1517
1618 # configure grid layout for the master window
1719 master .columnconfigure (2 , weight = 1 )
@@ -20,158 +22,210 @@ def __init__(self, master):
2022 # define light grey color for borders
2123 light_grey = "#C0C0C0"
2224
23- # ====================
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 )
2431
25- # personal information frame
26- self .personal_frame = Frame (master , relief = "solid" , highlightbackground = light_grey , highlightthickness = 1 )
27- self .personal_frame .grid (row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = "nsew" )
28-
29- # personal frame title
30- self .personal_title_label = Label (self .personal_frame , text = "Employee Information" , font = ("Arial" , 10 ))
31- self .personal_title_label .grid (row = 0 , column = 0 , columnspan = 2 , padx = 5 , pady = 5 , sticky = "w" )
32-
33- # first Name
34- self .first_name_label = Label (self .personal_frame , text = "First Name:" , font = ("Arial" , 10 ))
35- self .first_name_label .grid (row = 1 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
36- self .first_name_entry = Entry (self .personal_frame , font = ("Arial" , 10 ))
37- self .first_name_entry .grid (row = 1 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
38-
39- # last Name
40- self .last_name_label = Label (self .personal_frame , text = "Last Name:" , font = ("Arial" , 10 ))
41- self .last_name_label .grid (row = 2 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
42- self .last_name_entry = Entry (self .personal_frame , font = ("Arial" , 10 ))
43- self .last_name_entry .grid (row = 2 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
44-
45- # date of Birth
46- self .dob_label = Label (self .personal_frame , text = "Date of Birth:" , font = ("Arial" , 10 ))
47- self .dob_label .grid (row = 3 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
48- self .dob_entry = Entry (self .personal_frame , font = ("Arial" , 10 ))
49- self .dob_entry .grid (row = 3 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
50-
51- # gender
52- self .gender_label = Label (self .personal_frame , text = "Gender:" , font = ("Arial" , 10 ))
53- self .gender_label .grid (row = 4 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
54- self .gender_entry = Entry (self .personal_frame , font = ("Arial" , 10 ))
55- self .gender_entry .grid (row = 4 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
32+ # configure grid layout for the frames to expand properly
33+ self .configure_frame_grid ()
5634
35+ # adjust window size based on the content
36+ self .adjust_window_size ()
37+
5738 # ====================
5839
59- # contact information frame
60- self .contact_frame = Frame (master , relief = "solid" , highlightbackground = light_grey , highlightthickness = 1 )
61- self .contact_frame .grid (row = 1 , column = 0 , padx = 10 , pady = 10 , sticky = "nsew" )
62-
63- # contact frame title
64- self .contact_title_label = Label (self .contact_frame , text = "Contact Information" , font = ("Arial" , 10 ))
65- self .contact_title_label .grid (row = 0 , column = 0 , columnspan = 2 , padx = 5 , pady = 5 , sticky = "w" )
66-
67- # email Address
68- self .email_label = Label (self .contact_frame , text = "Email Address:" , font = ("Arial" , 10 ))
69- self .email_label .grid (row = 1 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
70- self .email_entry = Entry (self .contact_frame , font = ("Arial" , 10 ))
71- self .email_entry .grid (row = 1 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
72-
73- # phone number
74- self .phone_number_label = Label (self .contact_frame , text = "Phone Number:" , font = ("Arial" , 10 ))
75- self .phone_number_label .grid (row = 2 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
76- self .phone_number_entry = Entry (self .contact_frame , font = ("Arial" , 10 ))
77- self .phone_number_entry .grid (row = 2 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
78-
79- # home address
80- self .address_label = Label (self .contact_frame , text = "Home Address:" , font = ("Arial" , 10 ))
81- self .address_label .grid (row = 3 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
82- self .address_entry = Entry (self .contact_frame , font = ("Arial" , 10 ))
83- self .address_entry .grid (row = 3 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
84-
85- # zip code
86- self .zip_code_label = Label (self .contact_frame , text = "Zip Code:" , font = ("Arial" , 10 ))
87- self .zip_code_label .grid (row = 4 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
88- self .zip_code_entry = Entry (self .contact_frame , font = ("Arial" , 10 ))
89- self .zip_code_entry .grid (row = 4 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
40+ def create_personal_info_frame (self , border_color ):
41+ """
42+ create and place the personal information frame.
43+
44+ parameters:
45+ border_color (str): the color to use for the frame's border.
46+ """
47+ # create and place the personal information frame
48+ self .personal_frame = self .create_frame (border_color , 0 )
49+ self .create_label (self .personal_frame , "Employee Information" , 0 , 0 , 2 )
50+
51+ # create and place personal information fields
52+ self .create_label_entry (self .personal_frame , "First Name:" , 1 )
53+ self .create_label_entry (self .personal_frame , "Last Name:" , 2 )
54+ self .create_label_entry (self .personal_frame , "Date of Birth:" , 3 )
55+ self .create_label_entry (self .personal_frame , "Gender:" , 4 )
56+
57+ # ====================
9058
59+ def create_contact_info_frame (self , border_color ):
60+ """
61+ create and place the contact information frame.
62+
63+ parameters:
64+ border_color (str): the color to use for the frame's border.
65+ """
66+ # create and place the contact information frame
67+ self .contact_frame = self .create_frame (border_color , 1 )
68+ self .create_label (self .contact_frame , "Contact Information" , 0 , 0 , 2 )
69+
70+ # create and place contact information fields
71+ self .create_label_entry (self .contact_frame , "Email Address:" , 1 )
72+ self .create_label_entry (self .contact_frame , "Phone Number:" , 2 )
73+ self .create_label_entry (self .contact_frame , "Home Address:" , 3 )
74+ self .create_label_entry (self .contact_frame , "Zip Code:" , 4 )
75+
9176 # ====================
9277
93- # job information frame
94- self .job_frame = Frame (master , relief = "solid" , highlightbackground = light_grey , highlightthickness = 1 )
95- self .job_frame .grid (row = 2 , column = 0 , padx = 10 , pady = 10 , sticky = "nsew" )
96-
97- # job information title
98- self .job_frame_title = Label (self .job_frame , text = "Job Information" , font = ("Arial" , 10 ))
99- self .job_frame_title .grid (row = 0 , column = 0 , columnspan = 2 , padx = 5 , pady = 5 , sticky = "w" )
100-
101- # job title
102- self .job_title_label = Label (self .job_frame , text = "Job Title:" , font = ("Arial" , 10 ))
103- self .job_title_label .grid (row = 1 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
104- self .job_title_entry = Entry (self .job_frame , font = ("Arial" , 10 ))
105- self .job_title_entry .grid (row = 1 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
106-
107- # department
108- self .department_label = Label (self .job_frame , text = "Department:" , font = ("Arial" , 10 ))
109- self .department_label .grid (row = 2 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
110- self .department_entry = Entry (self .job_frame , font = ("Arial" , 10 ))
111- self .department_entry .grid (row = 2 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
112-
113- # date of hire
114- self .hire_date_label = Label (self .job_frame , text = "Hire Date:" , font = ("Arial" , 10 ))
115- self .hire_date_label .grid (row = 3 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
116- self .hire_date_entry = Entry (self .job_frame , font = ("Arial" , 10 ))
117- self .hire_date_entry .grid (row = 3 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
118-
119- # salary
120- self .salary_label = Label (self .job_frame , text = "Salary:" , font = ("Arial" , 10 ))
121- self .salary_label .grid (row = 4 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
122- self .salary_entry = Entry (self .job_frame , font = ("Arial" , 10 ))
123- self .salary_entry .grid (row = 4 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
78+ def create_job_info_frame (self , border_color ):
79+ """
80+ create and place the job information frame.
81+
82+ parameters:
83+ border_color (str): the color to use for the frame's border.
84+ """
85+ # create and place the job information frame
86+ self .job_frame = self .create_frame (border_color , 2 )
87+ self .create_label (self .job_frame , "Job Information" , 0 , 0 , 2 )
88+
89+ # create and place job information fields
90+ self .create_label_entry (self .job_frame , "Job Title:" , 1 )
91+ self .create_label_entry (self .job_frame , "Department:" , 2 )
92+ self .create_label_entry (self .job_frame , "Hire Date:" , 3 )
93+ self .create_label_entry (self .job_frame , "Salary:" , 4 )
12494
12595 # ====================
96+
97+ def create_emergency_contact_frame (self , border_color ):
98+ """
99+ create and place the emergency contact frame.
100+
101+ parameters:
102+ border_color (str): the color to use for the frame's border.
103+ """
104+ # create and place the emergency contact frame
105+ self .emergency_contact_frame = self .create_frame (border_color , 3 )
106+ self .create_label (self .emergency_contact_frame , "Emergency Information" , 0 , 0 , 2 )
107+
108+ # create and place emergency contact fields
109+ self .create_label_entry (self .emergency_contact_frame , "First Name:" , 1 )
110+ self .create_label_entry (self .emergency_contact_frame , "Last Name:" , 2 )
111+ self .create_label_entry (self .emergency_contact_frame , "Relationship:" , 3 )
112+ self .create_label_entry (self .emergency_contact_frame , "Phone Number:" , 4 )
126113
127- # emergency contact frame
128- self .emergency_contact_frame = Frame (master , relief = "solid" , highlightbackground = light_grey , highlightthickness = 1 )
129- self .emergency_contact_frame .grid (row = 3 , column = 0 , padx = 10 , pady = 10 , sticky = "nsew" )
130-
131- # emergency information title
132- self .emergency_contact_title = Label (self .emergency_contact_frame , text = "Emergency Information" , font = ("Arial" , 10 ))
133- self .emergency_contact_title .grid (row = 0 , column = 0 , columnspan = 2 , padx = 5 , pady = 5 , sticky = "w" )
134-
135- # emergency contact first name
136- self .e_fname_label = Label (self .emergency_contact_frame , text = "First Name:" , font = ("Arial" , 10 ))
137- self .e_fname_label .grid (row = 1 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
138- self .e_fname_entry = Entry (self .emergency_contact_frame , font = ("Arial" , 10 ))
139- self .e_fname_entry .grid (row = 1 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
140-
141- # emergency contact last name
142- self .elname_label = Label (self .emergency_contact_frame , text = "Last Name:" , font = ("Arial" , 10 ))
143- self .elname_label .grid (row = 2 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
144- self .elname_entry = Entry (self .emergency_contact_frame , font = ("Arial" , 10 ))
145- self .elname_entry .grid (row = 2 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
146-
147- # emergency contact relationship
148- self .e_relationship_label = Label (self .emergency_contact_frame , text = "Relationship:" , font = ("Arial" , 10 ))
149- self .e_relationship_label .grid (row = 3 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
150- self .e_relationship_entry = Entry (self .emergency_contact_frame , font = ("Arial" , 10 ))
151- self .e_relationship_entry .grid (row = 3 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
152-
153- # emergency contact number
154- self .e_phone_number_label = Label (self .emergency_contact_frame , text = "Phone Number:" , font = ("Arial" , 10 ))
155- self .e_phone_number_label .grid (row = 4 , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
156- self .e_phone_number_entry = Entry (self .emergency_contact_frame , font = ("Arial" , 10 ))
157- self .e_phone_number_entry .grid (row = 4 , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
114+ # ====================
115+
116+ def create_buttons_frame (self , border_color ):
117+ """
118+ Create and configure the buttons frame.
119+
120+ parameters:
121+ border_color (str): the color to use for the frame's border.
122+ """
123+ # Create a frame for buttons with specified border color
124+ 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
126+ self .buttons_frame .grid (row = 3 , column = 1 , padx = 10 , pady = 10 , sticky = "nsew" )
127+ # Add labels or buttons to the frame
128+ 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 ):
135+ """
136+ Create a button and place it in the buttons frame.
137+ """
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+
153+ def create_frame (self , border_color , row ):
154+ """
155+ create a frame with a specified border color and row placement.
156+
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.
160+
161+ returns:
162+ Frame: the created Tkinter frame.
163+ """
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" )
166+ frame .grid (row = row , column = 0 , padx = 10 , pady = 10 , sticky = "nsew" )
167+ return frame
168+
169+ # ====================
158170
159- # configure grid layout for the frames to expand properly
171+ def create_label (self , parent , text , row , column , columnspan = 1 ):
172+ """
173+ create and place a label in a specified parent widget.
174+
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.
181+ """
182+ # create and place a label in a specified parent widget
183+ label = Label (parent , text = text , font = ("Arial" , 10 ))
184+ label .grid (row = row , column = column , columnspan = columnspan , padx = 5 , pady = 5 , sticky = "w" )
185+
186+ # ====================
187+
188+ def create_label_entry (self , parent , text , row ):
189+ """
190+ create and place a label and entry widget pair.
191+
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.
196+
197+ returns:
198+ Entry: the created Tkinter entry widget.
199+ """
200+ # create and place a label and entry widget pair
201+ label = Label (parent , text = text , font = ("Arial" , 10 ))
202+ label .grid (row = row , column = 0 , padx = 5 , pady = 5 , sticky = "w" )
203+ entry = Entry (parent , font = ("Arial" , 10 ))
204+ entry .grid (row = row , column = 1 , padx = 10 , pady = 5 , sticky = "e" )
205+ return entry
206+
207+ # ====================
208+
209+ def configure_frame_grid (self ):
210+ """
211+ configure grid layout for all frames to expand properly.
212+ """
213+ # configure grid layout for all frames to expand properly
160214 self .personal_frame .columnconfigure (1 , weight = 1 )
161215 self .contact_frame .columnconfigure (1 , weight = 1 )
162216 self .job_frame .columnconfigure (1 , weight = 1 )
163217 self .emergency_contact_frame .columnconfigure (1 , weight = 1 )
164218
165219 # ====================
166-
167- # Adjust window size based on the content
168- self .adjust_window_size ()
169-
220+
170221 def adjust_window_size (self ):
171- # Update the window layout to calculate the total height
222+ """
223+ update the window layout to calculate the total height and adjust the window size.
224+ """
225+ # update the window layout to calculate the total height
172226 self .master .update_idletasks ()
173227
174- # Calculate the total height needed for all frames
228+ # calculate the total height needed for all frames
175229 total_height = (
176230 self .personal_frame .winfo_height () +
177231 self .contact_frame .winfo_height () +
@@ -180,18 +234,25 @@ def adjust_window_size(self):
180234 50 # additional padding between frames
181235 )
182236
183- # Set the window height to fit all frames
237+ # set the window height to fit all frames
184238 self .master .geometry (f"1400x{ total_height } " )
185239
240+ # ====================
241+
186242def main ():
187- """Initialize the Tkinter window application."""
243+ """
244+ initialize the tkinter window application.
245+ """
188246 # create the main window
189247 window = Tk ()
190248 # create an instance of the EmployeeApp class
191249 app = EmployeeApp (window )
192- # start the Tkinter event loop
250+ # start the tkinter event loop
193251 window .mainloop ()
194252
253+ # ====================
254+
195255if __name__ == "__main__" :
196256 # run the main function if the script is executed directly
197257 main ()
258+
0 commit comments