Having problem using tkinter to collect data and send to AddEmployeeManually class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leahakbashev
    New Member
    • Sep 2019
    • 1

    Having problem using tkinter to collect data and send to AddEmployeeManually class

    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()
    Last edited by gits; Sep 23 '19, 07:14 AM. Reason: added code tags
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    First, you must format you code in code tages so it can be read. Edit your post and format the code to get any help. Second do you have a specific problem? "Having problem using tkinter" is too vague to respond to. I did happen to notice
    Code:
    self.name = ttk.Entry(window).grid(row=0, column=1)
    grid() returns None to self.name will always be None. Print it to see for yourself. Am not willing to guess further about what other problems you are having or how your code is formatted.

    Comment

    Working...