Question: Here is the code I have as project 4 : import pandas as pd class EMSystem: def _ _ init _ _ ( self )

Here is the code I have as project 4:
import pandas as pd
class EMSystem:
def __init__(self):
self.employee_list =[]
self.current_log =[]
self.start()
def start(self):
self.printWelcomeMessage()
while True:
self.printAllOptions()
inp = int(input())
if inp ==1:
self.setEmployeeList()
elif inp ==2:
self.printEmployeeList()
elif inp ==3:
time = input("Enter the current time (HH:MM): ")
self.makeNewLog(time)
elif inp ==4:
break
else:
print("Invalid input. Please try again.")
def printWelcomeMessage(self):
print("Welcome to the Employee Monitoring System!")
def printAllOptions(self):
print("What do you want to do today? (input the number)")
print("1- Set the employee list")
print("2- Show the employee list")
print("3- Make a new timestamp")
print("4- Close the EM System")
def setEmployeeList(self):
file_name = input("Enter the file name (employee_list1.csv or employee_list2.txt): ")
try:
if file_name.endswith(".csv"):
self.employee_list = pd.read_csv(file_name).values.tolist()
elif file_name.endswith(".txt"):
with open(file_name, 'r') as f:
self.employee_list =[line.strip().split('\t') for line in f]
else:
print("Invalid file format. Please use .csv or .txt.")
except FileNotFoundError:
print(f"File '{file_name}' not found.")
except Exception as e:
print(f"An error occurred: {str(e)}")
def printEmployeeList(self):
if not self.employee_list:
print("Employee list is empty.")
else:
print("Employee List:")
for employee in self.employee_list:
print(f"ID: {employee[0]}, Name: {employee[1]}, Total Hours: {employee[2]}")
def makeNewLog(self, time):
if not self.employee_list:
print("Employee list is empty. Please set the employee list first.")
return
self.current_log =[(employee_id,"in", time) for employee_id,_,_ in self.employee_list]
while True:
employee_id = input("Enter employee ID to log in/out (blank to finish): ")
if not employee_id:
break
self.addEmployeeToLog(employee_id, "out" if self.current_log[0][1]=="in" else "in", time)
self.createTimestampLog()
def addEmployeeToLog(self, employee_id, status, time):
for i,(id,_, hours) in enumerate(self.employee_list):
if id == employee_id:
self.current_log[i]=(employee_id, status, time)
self.employee_list[i][2]+=1 if status == "out" else 0
break
def createTimestampLog(self):
print("
Timestamp Log:")
for employee_id, status, time in self.current_log:
employee = next(e for e in self.employee_list if e[0]== employee_id)
print(f"ID: {employee[0]}, Name: {employee[1]}, Status: {status}, Time: {time}, Total Hours: {employee[2]}")
with open("timestamp_log.txt","w") as f:
for employee_id, status, time in self.current_log:
employee = next(e for e in self.employee_list if e[0]== employee_id)
f.write(f"ID: {employee[0]}, Name: {employee[1]}, Status: {status}, Time: {time}, Total Hours: {employee[2]}
")
AksenchureCompany = EMSystem()
Now here is the revised code:
import tkinter as tk
from tkinter import ttk
import pandas as pd
class EMSystem:
def __init__(self):
self.window = tk.Tk()
self.window.title("Employee Monitoring System")
self.employee_list =[]
self.current_log =[]
self.create_gui()
self.window.mainloop()
def create_gui(self):
label = tk.Label(self.window, text="Employee ID:")
label.grid(row=0, column=0)
self.employee_entry = tk.Entry(self.window)
self.employee_entry.grid(row=0, column=1)
set_employee_button = tk.Button(self.window, text="Set Employee List", command=self.set_employee_list)
set_employee_button.grid(row=1, columnspan=2)
def set_employee_list(self):
filename = self.employee_entry.get()
try:
self.employee_list = pd.read_csv(filename).values.tolist()
print("Employee list loaded successfully.")
except FileNotFoundError:
print("File not found. Please check the filename.")
except Exception as e:
print("An error occurred:", str(e))
if __name__=="__main__":
system = EMSystem()
However, to satisfy the spec given in the image, the GUI created should display the 5 options as buttons in a single window which the current revised code does not satisfy. Please revise it again to satisfy the spec.
Problem: EM System, Improved
Update the EMSystem from Project 4 to have a GUI. The
Here is the code I have as project 4 : import

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!