Hey I'm trying to get a variable from a class but for some reason its not coming through. its probably really simple but I really cant think of anything
Here is the code its not done yet I've only made a login screen:
from tkinter import *
import tkinter.messagebox as tm
correct = False
#-------------Functions-----------------------------------------------------
class LoginMenu(Frame):
def __init__(self, master):
super().__init__(master)
self.label_2 = Label(self, text="Welcome to the rota system")
self.label_3 = Label(self, text="Please enter the password to continue:")
self.label_1 = Label(self, text="Password")
self.entry_1 = Entry(self)
self.label_1.grid(row=3, sticky=W)
self.label_2.grid(row=1, sticky=W)
self.label_3.grid(row=2, sticky=W)
self.entry_1.grid(row=3, sticky=W)
self.logbtn = Button(self, text="Login", command = self.login_btn_clicked)
self.logbtn.grid(columnspan=2)
self.pack()
def login_btn_clicked(self):
password = self.entry_1.get()
if password == "1234":
correct = True
else:
tm.showerror("Login error", "Incorrect password")
return correct
#-----------------Main-Program----------------------------------------------
window = Tk()
LoginMenu(window)
if correct == True:
print("Yay")
LoginMenu.self.destroy()
window.mainloop()
correctvariable is never declared when the password is incorrect, so it can not bereturn. Even if it is declared it will only exist in the scope of the class method. It is not a global variable and you should not use one inside a class.