0

In my program, once my user has logged in, a new class is opened in which a function is loaded to check if the users details are correct, and then proceeds to either close the login window, display an error message, and then reload the page. And if the user logs in successfully, then the login screen closes and the program continues. However, I'm not able to close the windows which were opened in the Main class, but I can open windows in the other classes. How can I make it so that I can close the login screen in the teacher class.

class Main:

    def __init__(self, screen):
        self._frame = None
        self.username = StringVar()
        self.password = StringVar()
        self.var_FName = StringVar()
        self.var_SName = StringVar()
        self.var_password1 = StringVar()
        self.var_usertype = StringVar()
        self.UserID = StringVar()



    def Main_menu(self):
        screen.geometry("300x250")
        screen.title("Manager of stuff")
        Label(screen, text = "Login Menu", bg = "light blue", width = "300", font = ('',35),pady = 10).pack()
        Label(text = "").pack()
        Button(text = "Login", height = "2", width = "30", command = self.login).pack()
        Label(text = "").pack()
        Button(text = "Register",height = "2", width = "30", command = self.register).pack()

    def login(self):
        login = Toplevel(screen) #this is the screen im trying to close
        login.title("Login")
        login.geometry("500x450")

        Label(login, text = "Please enter your username and password below: ").pack()
        Label(login, text = "").pack()
        Label(login, text = "Username: ").pack()
        Entry(login, textvariable = self.username).pack()
        Label(login, text = "").pack()
        Label(login, text = "Password: ").pack()
        Entry(login, textvariable = self.password, show= "*").pack()
        Label(login, text = "").pack()
        Button(login, text = "Login As a Teacher", width = 20, height = 3, command = lambda : Teacher.LoginFunc(self)).pack()
        Label(login, text = "").pack()
        Button(login, text = "Login As a Student", width = 20, height = 3, command = lambda : Student.LoginFunc(self)).pack()
        Label(login, text = "").pack()
        Button(login, text = "Back", width = 30, height = 4, command = lambda : login.destroy()).pack()
        login.mainloop()
class Teacher (Main):
  def __init__(self, screen):
    self._frame = None

  def LoginFunc(self):
        while True:
            with sqlite3.connect('MyComputerScience.db') as db:
                cursor = db.cursor()
            find_user = ("SELECT * FROM users WHERE username = ? AND password = ? AND usertype = 'Teacher'")
            cursor.execute(find_user, (self.username.get(), self.password.get()))
            results = cursor.fetchall()
            if results:
                for i in results:
                    #Label(Main.login, text = "Log-in successful!", fg = "GREEN", font = "Calibri").pack()
                    Teacher.teachmain(self)

            else:
                Main.logindestroy(self, login)
                ms.showerror("Error", "Incorrect Details")
                Main.login(self)  
            break
bruhbruh
  • 27
  • 5
  • so your goal is to close the login window when the user credentials are correct ? – JimShapedCoding Jan 01 '20 at 13:38
  • to close the entire toplevel aswell, and also close just the login page if the details are incorrect – bruhbruh Jan 01 '20 at 13:48
  • 1
    Read [Tkinter understanding mainloop](https://stackoverflow.com/questions/29158220/tkinter-understanding-mainloop) and [tkinter-dialog-windows](http://effbot.org/tkinterbook/tkinter-dialog-windows.htm) – stovfl Jan 01 '20 at 14:13

0 Answers0