0
Hello I am developing a python application using Tkinter but I don’t know why it is giving me error. I was inspired by an example. My code.
from tkinter import *
win = Tk()
win.geometry("400x150")
class Application:
def __init__(self, master=None):
self.title = Label(win,text="Please enter the username and password",font=('Helvetica',13))
self.title.pack()
self.suc = Label(win,font=('Helvetica',10))
self.suc.pack()
self.username = Entry(win,width=20)
self.username.pack()
self.password = Entry(win,show="*",width=20)
self.password.pack()
self.btnConfirm = Button(win, text="Enter",font=('Helvetica bold',10),command=self.enter)
self.btnConfirm.pack()
self.btnQuit = Button(win, text="Quit",font=('Helvetica bold',10),command=self.exit)
self.btnQuit.pack()
def exit(self):
win.destroy()
def enter(self):
if username=="admin" and password=="123":
self.suc["text"] = "Sucess"
else:
self.suc["text"] = "Error"
Application(win)
win.mainloop()
The error that happens when clicking the Enter button:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1776.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\ESFA\Desktop\Project Python\index1.py", line 29, in enter
if username=="admin" and password=="123":
NameError: name 'username' is not defined
forgot self in front of username and password
– Elton Nunes
I’ll try that, thanks
– GFS_0508
in its code also lacked to use Stringvar, this is thing of Tkinter, of a searched
– Elton Nunes
ok thank you for informing
– GFS_0508