This my very first time interact with Tkinter and I'm trying to make a sign up form application but it it keep showing error when I tried to save the info into a txt file But the application do run it only get the error when I press the Button that was meant to save the info
Here the codes:
from tkinter import messagebox
main = Tk()
main.title('Sign up application')
main.resizable(0, 0)
main.config(bg='#CCCCCC')
genderr = StringVar()
genderr.set('Male')
Label(main, text='Name: ', bg='#CCCCCC', font=('Times', 12)).grid(column=0, row=1)
Label(main, text='Age: ', bg='#CCCCCC', font=('Times', 12)).grid(column=0, row=2)
Label(main, text='Email: ', bg='#CCCCCC', font=('Times', 12)).grid(column=0, row=3)
Label(main, text='Number: ', bg='#CCCCCC', font=('Times', 12)).grid(column=0, row=4)
Label(main, text='Gender: ', bg='#CCCCCC', font=('Times', 12)).grid(column=0, row=5)
Label(main, text='Password: ', bg='#CCCCCC', font=('Times', 12)).grid(column=0, row=6)
Label(main, text='Re-Enter Password: ', bg='#CCCCCC', font=('Times', 12)).grid(column=0, row=7)
tName=Entry(main, bg='#b7baa6', width=30).grid(column=1, row=1, padx=10, pady=10, sticky=E)
tAge=Entry(main, bg='#b7baa6', width=30).grid(column=1, row=2, padx=10, pady=10, sticky=E)
tEmail=Entry(main, bg='#b7baa6', width=30).grid(column=1, row=3, padx=10, pady=10, sticky=E)
tNumber=Entry(main, bg='#b7baa6', width=30 ).grid(column=1, row=4, padx=10, pady=10, sticky=E)
gender1=Radiobutton(main, activebackground='#d0e63e', text='Male', value='Male', variable=genderr).place(x=150, y=155)
gender2=Radiobutton(main, activebackground='#d0e63e', text='Female', value='Female', variable=genderr).place(x=260, y=155)
tPass=Entry(main, bg='#b7baa6', width=30, show=('*')).grid(column=1, row=6, padx=10, pady=10, sticky=E)
tRePass=Entry(main, bg='#b7baa6', width=30, show='*').grid(column=1, row=7, padx=10, pady=10, sticky=E)
def invalid():
if tName.get() == '':
messagebox.showerror('Error', 'You need to complete the form!')
return
elif tAge.get() == '':
messagebox.showerror('Error', 'You need to complete the form!')
return
elif tRePass.get() == '':
messagebox.showerror('Error', 'You need to complete the form!')
return
elif tPass.get() == '':
messagebox.showerror('Error', 'You need to complete the form!')
return
elif tEmail.get() == '':
messagebox.showerror('Error', 'You need to complete the form!')
return
elif tNumber.get() == '':
messagebox.showerror('Error', 'You need to complete the form!')
return
elif tPass.get() != tRePass.get():
messagebox.showerror('Error', 'Password did not match')
return
else:
f = open('Info.txt', 'a')
f.write('Name: ', tName.get(), '\nEmail: ', tEmail.get(), '\nNumber: ', tNumber.get(), '\nGender: ', genderr.get(), '\nPassword: ', tPass.get())
f.close()
messagebox.showinfo('Success', 'You have succesed sign up')
return
But = Button(main, text='Sign up', command= invalid).grid(column=1, row=8)
main.mainloop()```
***PS C:\Users\Hp\Documents> & C:/Users/Hp/AppData/Local/Programs/Python/Python310/python.exe c:/Users/Hp/Documents/gui.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Hp\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "c:\Users\Hp\Documents\gui.py", line 31, in invalid
if tName.get() == '':
AttributeError: 'NoneType' object has no attribute 'get'***