0% found this document useful (0 votes)
38 views3 pages

GUI

This Python code defines functions to create, add, search, delete, and display employee records stored in a dictionary. It initializes an empty employee dictionary and sets up a GUI with labels, entries, and buttons to call the functions to manage the employee data stored in the dictionary. When a function is called, it will update the status label to notify the user of the action performed.

Uploaded by

qq99xyhqm4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

GUI

This Python code defines functions to create, add, search, delete, and display employee records stored in a dictionary. It initializes an empty employee dictionary and sets up a GUI with labels, entries, and buttons to call the functions to manage the employee data stored in the dictionary. When a function is called, it will update the status label to notify the user of the action performed.

Uploaded by

qq99xyhqm4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import tkinter as tk

from tkinter import messagebox

# Initialize an empty dictionary to store employee data


employee_dict = {}

def create_employee():
try:
emp_id = int(entry_emp_id.get())
emp_name = entry_emp_name.get()
emp_dob = entry_emp_dob.get()
designation = entry_designation.get()
employee_dict[emp_id] = [emp_name, emp_dob, designation]
update_status_label(f"Employee {emp_id} created")
except ValueError:
messagebox.showerror("Error", "Invalid input for Employee ID")

def add_employee():
try:
emp_id = int(entry_emp_id.get())
emp_name = entry_emp_name.get()
emp_dob = entry_emp_dob.get()
designation = entry_designation.get()
employee_dict[emp_id] = [emp_name, emp_dob, designation]
update_status_label(f"Employee {emp_id} added")
except ValueError:
messagebox.showerror("Error", "Invalid input for Employee ID")

def search_employee():
try:
emp_id = int(entry_search_emp_id.get())
if emp_id in employee_dict:
result_label.config(text=f"Employee {emp_id} Details: {employee_dict[emp_id]}")
else:
result_label.config(text=f"Employee {emp_id} not found")
except ValueError:
messagebox.showerror("Error", "Invalid input for Employee ID")

def delete_employee():
try:
emp_id = int(entry_delete_emp_id.get())
if emp_id in employee_dict:
employee_dict.pop(emp_id)
update_status_label(f"Employee {emp_id} deleted")
else:
update_status_label(f"Employee {emp_id} not found")
except ValueError:
messagebox.showerror("Error", "Invalid input for Employee ID")

def display_employees():
if not employee_dict:
update_status_label("No Employee Details Found to Print")
else:
result_label.config(text=employee_dict)
def update_status_label(message):
status_label.config(text=message)

root = tk.Tk()
root.title("Employee Database Management")

frame = tk.Frame(root, padx=20, pady=20)


frame.pack()

label_emp_id = tk.Label(frame, text="Employee ID:")


label_emp_id.grid(row=0, column=0)
entry_emp_id = tk.Entry(frame, width=10)
entry_emp_id.grid(row=0, column=1)

label_emp_name = tk.Label(frame, text="Employee Name:")


label_emp_name.grid(row=1, column=0)
entry_emp_name = tk.Entry(frame, width=20)
entry_emp_name.grid(row=1, column=1)

label_emp_dob = tk.Label(frame, text="DOB:")


label_emp_dob.grid(row=2, column=0)
entry_emp_dob = tk.Entry(frame, width=10)
entry_emp_dob.grid(row=2, column=1)

label_designation = tk.Label(frame, text="Designation:")


label_designation.grid(row=3, column=0)
entry_designation = tk.Entry(frame, width=20)
entry_designation.grid(row=3, column=1)

create_button = tk.Button(frame, text="Create Employee", command=create_employee)


create_button.grid(row=4, column=0, columnspan=2)
add_button = tk.Button(frame, text="Add Employee", command=add_employee)
add_button.grid(row=5, column=0, columnspan=2)

label_search_emp_id = tk.Label(frame, text="Search Employee ID:")


label_search_emp_id.grid(row=6, column=0)
entry_search_emp_id = tk.Entry(frame, width=10)
entry_search_emp_id.grid(row=6, column=1)
search_button = tk.Button(frame, text="Search Employee", command=search_employee)
search_button.grid(row=7, column=0, columnspan=2)

label_delete_emp_id = tk.Label(frame, text="Delete Employee ID:")


label_delete_emp_id.grid(row=8, column=0)
entry_delete_emp_id = tk.Entry(frame, width=10)
entry_delete_emp_id.grid(row=8, column=1)
delete_button = tk.Button(frame, text="Delete Employee", command=delete_employee)
delete_button.grid(row=9, column=0, columnspan=2)

display_button = tk.Button(frame, text="Display Employees", command=display_employees)


display_button.grid(row=10, column=0, columnspan=2)

status_label = tk.Label(root, text="", pady=10)


status_label.pack()
result_label = tk.Label(root, text="")
result_label.pack()
root.mainloop()

You might also like