Skip to content

Commit

Permalink
Update employee_temp.py
Browse files Browse the repository at this point in the history
  • Loading branch information
arsalan-dev-engineer authored Jul 30, 2024
1 parent 5844865 commit 9e55a1a
Showing 1 changed file with 204 additions and 143 deletions.
347 changes: 204 additions & 143 deletions projects/employee_temp.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from tkinter import *
from tkinter import messagebox

class EmployeeApp:
def __init__(self, master):
# Initialize the main window
"""
initialize the main window and configure its layout.
parameters:
master (Tk): the root Tkinter window instance.
"""
# initialize the main window
self.master = master
master.geometry("1400x800")
# make the window non-resizable
master.resizable(0, 0)
# set the title of the window
master.geometry("1400x750")
master.resizable(0, 0) # make the window non-resizable
master.title("Employee Database")
# keep the window on top
master.attributes("-topmost", True)
master.attributes("-topmost", True) # keep the window on top

# configure grid layout for the master window
master.columnconfigure(2, weight=1)
Expand All @@ -20,158 +22,210 @@ def __init__(self, master):
# define light grey color for borders
light_grey = "#C0C0C0"

# ====================
# create and configure frames for various sections of the form
self.create_personal_info_frame(light_grey)
self.create_contact_info_frame(light_grey)
self.create_job_info_frame(light_grey)
self.create_emergency_contact_frame(light_grey)
self.create_buttons_frame(light_grey)

# personal information frame
self.personal_frame = Frame(master, relief="solid", highlightbackground=light_grey, highlightthickness=1)
self.personal_frame.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")

# personal frame title
self.personal_title_label = Label(self.personal_frame, text="Employee Information", font=("Arial", 10))
self.personal_title_label.grid(row=0, column=0, columnspan=2, padx=5, pady=5, sticky="w")

# first Name
self.first_name_label = Label(self.personal_frame, text="First Name:", font=("Arial", 10))
self.first_name_label.grid(row=1, column=0, padx=5, pady=5, sticky="w")
self.first_name_entry = Entry(self.personal_frame, font=("Arial", 10))
self.first_name_entry.grid(row=1, column=1, padx=10, pady=5, sticky="e")

# last Name
self.last_name_label = Label(self.personal_frame, text="Last Name:", font=("Arial", 10))
self.last_name_label.grid(row=2, column=0, padx=5, pady=5, sticky="w")
self.last_name_entry = Entry(self.personal_frame, font=("Arial", 10))
self.last_name_entry.grid(row=2, column=1, padx=10, pady=5, sticky="e")

# date of Birth
self.dob_label = Label(self.personal_frame, text="Date of Birth:", font=("Arial", 10))
self.dob_label.grid(row=3, column=0, padx=5, pady=5, sticky="w")
self.dob_entry = Entry(self.personal_frame, font=("Arial", 10))
self.dob_entry.grid(row=3, column=1, padx=10, pady=5, sticky="e")

# gender
self.gender_label = Label(self.personal_frame, text="Gender:", font=("Arial", 10))
self.gender_label.grid(row=4, column=0, padx=5, pady=5, sticky="w")
self.gender_entry = Entry(self.personal_frame, font=("Arial", 10))
self.gender_entry.grid(row=4, column=1, padx=10, pady=5, sticky="e")
# configure grid layout for the frames to expand properly
self.configure_frame_grid()

# adjust window size based on the content
self.adjust_window_size()

# ====================

# contact information frame
self.contact_frame = Frame(master, relief="solid", highlightbackground=light_grey, highlightthickness=1)
self.contact_frame.grid(row=1, column=0, padx=10, pady=10, sticky="nsew")

# contact frame title
self.contact_title_label = Label(self.contact_frame, text="Contact Information", font=("Arial", 10))
self.contact_title_label.grid(row=0, column=0, columnspan=2, padx=5, pady=5, sticky="w")

# email Address
self.email_label = Label(self.contact_frame, text="Email Address:", font=("Arial", 10))
self.email_label.grid(row=1, column=0, padx=5, pady=5, sticky="w")
self.email_entry = Entry(self.contact_frame, font=("Arial", 10))
self.email_entry.grid(row=1, column=1, padx=10, pady=5, sticky="e")

# phone number
self.phone_number_label = Label(self.contact_frame, text="Phone Number:", font=("Arial", 10))
self.phone_number_label.grid(row=2, column=0, padx=5, pady=5, sticky="w")
self.phone_number_entry = Entry(self.contact_frame, font=("Arial", 10))
self.phone_number_entry.grid(row=2, column=1, padx=10, pady=5, sticky="e")

# home address
self.address_label = Label(self.contact_frame, text="Home Address:", font=("Arial", 10))
self.address_label.grid(row=3, column=0, padx=5, pady=5, sticky="w")
self.address_entry = Entry(self.contact_frame, font=("Arial", 10))
self.address_entry.grid(row=3, column=1, padx=10, pady=5, sticky="e")

# zip code
self.zip_code_label = Label(self.contact_frame, text="Zip Code:", font=("Arial", 10))
self.zip_code_label.grid(row=4, column=0, padx=5, pady=5, sticky="w")
self.zip_code_entry = Entry(self.contact_frame, font=("Arial", 10))
self.zip_code_entry.grid(row=4, column=1, padx=10, pady=5, sticky="e")
def create_personal_info_frame(self, border_color):
"""
create and place the personal information frame.
parameters:
border_color (str): the color to use for the frame's border.
"""
# create and place the personal information frame
self.personal_frame = self.create_frame(border_color, 0)
self.create_label(self.personal_frame, "Employee Information", 0, 0, 2)

# create and place personal information fields
self.create_label_entry(self.personal_frame, "First Name:", 1)
self.create_label_entry(self.personal_frame, "Last Name:", 2)
self.create_label_entry(self.personal_frame, "Date of Birth:", 3)
self.create_label_entry(self.personal_frame, "Gender:", 4)

# ====================

def create_contact_info_frame(self, border_color):
"""
create and place the contact information frame.
parameters:
border_color (str): the color to use for the frame's border.
"""
# create and place the contact information frame
self.contact_frame = self.create_frame(border_color, 1)
self.create_label(self.contact_frame, "Contact Information", 0, 0, 2)

# create and place contact information fields
self.create_label_entry(self.contact_frame, "Email Address:", 1)
self.create_label_entry(self.contact_frame, "Phone Number:", 2)
self.create_label_entry(self.contact_frame, "Home Address:", 3)
self.create_label_entry(self.contact_frame, "Zip Code:", 4)

# ====================

# job information frame
self.job_frame = Frame(master, relief="solid", highlightbackground=light_grey, highlightthickness=1)
self.job_frame.grid(row=2, column=0, padx=10, pady=10, sticky="nsew")

# job information title
self.job_frame_title = Label(self.job_frame, text="Job Information", font=("Arial", 10))
self.job_frame_title.grid(row=0, column=0, columnspan=2, padx=5, pady=5, sticky="w")

# job title
self.job_title_label = Label(self.job_frame, text="Job Title:", font=("Arial", 10))
self.job_title_label.grid(row=1, column=0, padx=5, pady=5, sticky="w")
self.job_title_entry = Entry(self.job_frame, font=("Arial", 10))
self.job_title_entry.grid(row=1, column=1, padx=10, pady=5, sticky="e")

# department
self.department_label = Label(self.job_frame, text="Department:", font=("Arial", 10))
self.department_label.grid(row=2, column=0, padx=5, pady=5, sticky="w")
self.department_entry = Entry(self.job_frame, font=("Arial", 10))
self.department_entry.grid(row=2, column=1, padx=10, pady=5, sticky="e")

# date of hire
self.hire_date_label = Label(self.job_frame, text="Hire Date:", font=("Arial", 10))
self.hire_date_label.grid(row=3, column=0, padx=5, pady=5, sticky="w")
self.hire_date_entry = Entry(self.job_frame, font=("Arial", 10))
self.hire_date_entry.grid(row=3, column=1, padx=10, pady=5, sticky="e")

# salary
self.salary_label = Label(self.job_frame, text="Salary:", font=("Arial", 10))
self.salary_label.grid(row=4, column=0, padx=5, pady=5, sticky="w")
self.salary_entry = Entry(self.job_frame, font=("Arial", 10))
self.salary_entry.grid(row=4, column=1, padx=10, pady=5, sticky="e")
def create_job_info_frame(self, border_color):
"""
create and place the job information frame.
parameters:
border_color (str): the color to use for the frame's border.
"""
# create and place the job information frame
self.job_frame = self.create_frame(border_color, 2)
self.create_label(self.job_frame, "Job Information", 0, 0, 2)

# create and place job information fields
self.create_label_entry(self.job_frame, "Job Title:", 1)
self.create_label_entry(self.job_frame, "Department:", 2)
self.create_label_entry(self.job_frame, "Hire Date:", 3)
self.create_label_entry(self.job_frame, "Salary:", 4)

# ====================

def create_emergency_contact_frame(self, border_color):
"""
create and place the emergency contact frame.
parameters:
border_color (str): the color to use for the frame's border.
"""
# create and place the emergency contact frame
self.emergency_contact_frame = self.create_frame(border_color, 3)
self.create_label(self.emergency_contact_frame, "Emergency Information", 0, 0, 2)

# create and place emergency contact fields
self.create_label_entry(self.emergency_contact_frame, "First Name:", 1)
self.create_label_entry(self.emergency_contact_frame, "Last Name:", 2)
self.create_label_entry(self.emergency_contact_frame, "Relationship:", 3)
self.create_label_entry(self.emergency_contact_frame, "Phone Number:", 4)

# emergency contact frame
self.emergency_contact_frame = Frame(master, relief="solid", highlightbackground=light_grey, highlightthickness=1)
self.emergency_contact_frame.grid(row=3, column=0, padx=10, pady=10, sticky="nsew")

# emergency information title
self.emergency_contact_title = Label(self.emergency_contact_frame, text="Emergency Information", font=("Arial", 10))
self.emergency_contact_title.grid(row=0, column=0, columnspan=2, padx=5, pady=5, sticky="w")

# emergency contact first name
self.e_fname_label = Label(self.emergency_contact_frame, text="First Name:", font=("Arial", 10))
self.e_fname_label.grid(row=1, column=0, padx=5, pady=5, sticky="w")
self.e_fname_entry = Entry(self.emergency_contact_frame, font=("Arial", 10))
self.e_fname_entry.grid(row=1, column=1, padx=10, pady=5, sticky="e")

# emergency contact last name
self.elname_label = Label(self.emergency_contact_frame, text="Last Name:", font=("Arial", 10))
self.elname_label.grid(row=2, column=0, padx=5, pady=5, sticky="w")
self.elname_entry = Entry(self.emergency_contact_frame, font=("Arial", 10))
self.elname_entry.grid(row=2, column=1, padx=10, pady=5, sticky="e")

# emergency contact relationship
self.e_relationship_label = Label(self.emergency_contact_frame, text="Relationship:", font=("Arial", 10))
self.e_relationship_label.grid(row=3, column=0, padx=5, pady=5, sticky="w")
self.e_relationship_entry = Entry(self.emergency_contact_frame, font=("Arial", 10))
self.e_relationship_entry.grid(row=3, column=1, padx=10, pady=5, sticky="e")

# emergency contact number
self.e_phone_number_label = Label(self.emergency_contact_frame, text="Phone Number:", font=("Arial", 10))
self.e_phone_number_label.grid(row=4, column=0, padx=5, pady=5, sticky="w")
self.e_phone_number_entry = Entry(self.emergency_contact_frame, font=("Arial", 10))
self.e_phone_number_entry.grid(row=4, column=1, padx=10, pady=5, sticky="e")
# ====================

def create_buttons_frame(self, border_color):
"""
Create and configure the buttons frame.
parameters:
border_color (str): the color to use for the frame's border.
"""
# Create a frame for buttons with specified border color
self.buttons_frame = Frame(self.master, relief="solid", highlightbackground=border_color, highlightthickness=1)
# Place the frame in the grid at the bottom, right of the emergency_contact_frame
self.buttons_frame.grid(row=3, column=1, padx=10, pady=10, sticky="nsew")
# Add labels or buttons to the frame
self.create_label(self.buttons_frame, "Options", 0, 0, 1)
# create button within the frame
self.create_button()

# ====================

def create_button(self):
"""
Create a button and place it in the buttons frame.
"""
# create button and add it to buttons frame
add_button = Button(self.buttons_frame, text="Add", width=10, height=2)
add_button.grid(row=1, column=0, padx=5, pady=5)

delete_button = Button(self.buttons_frame, text="Delete", width=10, height=2)
delete_button.grid(row=2, column=0, padx=5, pady=5)

view_button = Button(self.buttons_frame, text="View", width=10, height=2)
view_button.grid(row=1, column=1, padx=5, pady=5)

export_button = Button(self.buttons_frame, text="Export", width=10, height=2)
export_button.grid(row=2, column=1, padx=5, pady=5)

# ====================

def create_frame(self, border_color, row):
"""
create a frame with a specified border color and row placement.
parameters:
border_color (str): the color to use for the frame's border.
row (int): the row index where the frame will be placed in the grid.
returns:
Frame: the created Tkinter frame.
"""
# create a frame with a specified border color and row placement
frame = Frame(self.master, relief="solid", highlightbackground=border_color, highlightthickness=1, highlightcolor="#C0C0C0")
frame.grid(row=row, column=0, padx=10, pady=10, sticky="nsew")
return frame

# ====================

# configure grid layout for the frames to expand properly
def create_label(self, parent, text, row, column, columnspan=1):
"""
create and place a label in a specified parent widget.
parameters:
parent (Frame): the parent widget where the label will be placed.
text (str): the text to display on the label.
row (int): the row index where the label will be placed in the grid.
column (int): the column index where the label will be placed in the grid.
columnspan (int, optional): the number of columns the label should span. default is 1.
"""
# create and place a label in a specified parent widget
label = Label(parent, text=text, font=("Arial", 10))
label.grid(row=row, column=column, columnspan=columnspan, padx=5, pady=5, sticky="w")

# ====================

def create_label_entry(self, parent, text, row):
"""
create and place a label and entry widget pair.
parameters:
parent (Frame): the parent widget where the label and entry will be placed.
text (str): the text to display on the label.
row (int): the row index where the label and entry will be placed in the grid.
returns:
Entry: the created Tkinter entry widget.
"""
# create and place a label and entry widget pair
label = Label(parent, text=text, font=("Arial", 10))
label.grid(row=row, column=0, padx=5, pady=5, sticky="w")
entry = Entry(parent, font=("Arial", 10))
entry.grid(row=row, column=1, padx=10, pady=5, sticky="e")
return entry

# ====================

def configure_frame_grid(self):
"""
configure grid layout for all frames to expand properly.
"""
# configure grid layout for all frames to expand properly
self.personal_frame.columnconfigure(1, weight=1)
self.contact_frame.columnconfigure(1, weight=1)
self.job_frame.columnconfigure(1, weight=1)
self.emergency_contact_frame.columnconfigure(1, weight=1)

# ====================

# Adjust window size based on the content
self.adjust_window_size()


def adjust_window_size(self):
# Update the window layout to calculate the total height
"""
update the window layout to calculate the total height and adjust the window size.
"""
# update the window layout to calculate the total height
self.master.update_idletasks()

# Calculate the total height needed for all frames
# calculate the total height needed for all frames
total_height = (
self.personal_frame.winfo_height() +
self.contact_frame.winfo_height() +
Expand All @@ -180,18 +234,25 @@ def adjust_window_size(self):
50 # additional padding between frames
)

# Set the window height to fit all frames
# set the window height to fit all frames
self.master.geometry(f"1400x{total_height}")

# ====================

def main():
"""Initialize the Tkinter window application."""
"""
initialize the tkinter window application.
"""
# create the main window
window = Tk()
# create an instance of the EmployeeApp class
app = EmployeeApp(window)
# start the Tkinter event loop
# start the tkinter event loop
window.mainloop()

# ====================

if __name__ == "__main__":
# run the main function if the script is executed directly
main()

0 comments on commit 9e55a1a

Please sign in to comment.