By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,960 Members | 2,232 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,960 IT Pros & Developers. It's quick & easy.

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

P: 1
Expand|Select|Wrap|Line Numbers
  1. import tkinter
  2. from tkinter import ttk
  3.  
  4. window = tkinter.Tk()
  5. window.title("Employees Management Form")
  6. window.geometry('600x600')
  7. window.configure(background="white");
  8.  
  9. class EmployeeForm():
  10.  
  11.     def __init__(self):
  12.         #labels for the Entries
  13.         lblName = ttk.Label(window, text="Name").grid(row=0, column=0)
  14.         lblId = ttk.Label(window, text="Id").grid(row=1, column=0)
  15.         lblPhone = ttk.Label(window, text="Phone Number").grid(row=2, column=0)
  16.         lblAge = ttk.Label(window, text="Age").grid(row=3, column=0)
  17.         #Entries
  18.         self.name = ttk.Entry(window).grid(row=0, column=1)
  19.         self.id = ttk.Entry(window).grid(row=1, column=1)
  20.         self.phone = ttk.Entry(window).grid(row=2, column=1)
  21.         self.age = ttk.Entry(window).grid(row=3, column=1)
  22.         #Submit Button
  23.         self.button = ttk.Button(window, text="Submit", command=self.on_button()).grid(row=4, column=1)
  24.  
  25.     #when Submit is press the data is sent to Add Empl manually class
  26.     def on_button(self):
  27.         employee = AddEmployeeManually(self.name, self.id, self.phone, self.phone)
  28.         employee.setData()
  29.         window.mainloop()
  30.  
  31. class AddEmployeeManually():
  32.     def __init__(self, name, id, age, phone):
  33.         self.name = name
  34.         self.phone = phone
  35.         self.age = age
  36.         self.id = id
  37.  
  38.     def setData(self):
  39.         employees = open('Employees.txt', 'a')
  40.         try:
  41.             employees.write(self.id)
  42.             employees.write(self.name)
  43.             employees.write(self.phone)
  44.             employees.write(self.age)
  45.             employees.write('\n')
  46.         except:
  47.             print('Error!')
  48.  
  49. def main():
  50.     choice = int(input("Please type: 1 to Add Employee Manually, 2 to Add from file and 3 to Delete Employee: \n"))
  51.     if choice == 1:
  52.         chosen = EmployeeForm()
  53.     elif choice == 2:
  54.         print("File import needs to be build!")
  55.     elif choice == 3:
  56.         print("Delete class needs to be build!")
  57.     else:
  58.         print ("Not correct choice!")
  59. if __name__ == "__main__":
  60.     main()
3 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
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
Expand|Select|Wrap|Line Numbers
  1. 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.
3 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.