Code:
import tkinter from tkinter import ttk window = tkinter.Tk() window.title("Employees Management Form") window.geometry('600x600') window.configure(background="white"); class EmployeeForm(): def __init__(self): #labels for the Entries lblName = ttk.Label(window, text="Name").grid(row=0, column=0) lblId = ttk.Label(window, text="Id").grid(row=1, column=0) lblPhone = ttk.Label(window, text="Phone Number").grid(row=2, column=0) lblAge = ttk.Label(window, text="Age").grid(row=3, column=0) #Entries self.name = ttk.Entry(window).grid(row=0, column=1) self.id = ttk.Entry(window).grid(row=1, column=1) self.phone = ttk.Entry(window).grid(row=2, column=1) self.age = ttk.Entry(window).grid(row=3, column=1) #Submit Button self.button = ttk.Button(window, text="Submit", command=self.on_button()).grid(row=4, column=1) #when Submit is press the data is sent to Add Empl manually class def on_button(self): employee = AddEmployeeManually(self.name, self.id, self.phone, self.phone) employee.setData() window.mainloop() class AddEmployeeManually(): def __init__(self, name, id, age, phone): self.name = name self.phone = phone self.age = age self.id = id def setData(self): employees = open('Employees.txt', 'a') try: employees.write(self.id) employees.write(self.name) employees.write(self.phone) employees.write(self.age) employees.write('\n') except: print('Error!') def main(): choice = int(input("Please type: 1 to Add Employee Manually, 2 to Add from file and 3 to Delete Employee: \n")) if choice == 1: chosen = EmployeeForm() elif choice == 2: print("File import needs to be build!") elif choice == 3: print("Delete class needs to be build!") else: print ("Not correct choice!") if __name__ == "__main__": main()
Comment