title: How to remove the login window when a toplevel is opened?
body: <p>So this is my code below for a login menu. Once the user has logged on I want the login menu to be either hidden or deleted. I've tried <code>.withdraw()</code> and <code>.destroy()</code>. I'm certain that I'm placing the code in the wrong places, any assistance would be much appreciated!</p>
  
  <pre><code>from tkinter import *
  import tkinter as tk
  import sqlite3
  import hashlib
  import os
  import weakref
  
  
  def main():
    root = Tk()
    width = 600 #sets the width of the window
    height = 600 #sets the height of the window
    widthScreen = root.winfo_screenwidth() #gets the width of the screen
    heightScreen = root.winfo_screenheight() #gets the height of the screen
    x = (widthScreen/2) - (width/2) #finds the center value of x
    y = (heightScreen/2) - (height/2) #finds the center value of y
    root.geometry('%dx%d+%d+%d' % (width, height, x, y))#places screen in center
    root.resizable(width=False, height=False)#Ensures that the window size cannot be changed 
    filename = PhotoImage(file = 'Login.gif') #gets the image from directory
    background_label = Label(image=filename) #makes the image
    background_label.place(x=0, y=0, relwidth=1, relheight=1)#palces the image
    logins = login(root)
    root.mainloop()
  
  class login(Tk):
    def __init__(self, master):
      self.__username = StringVar()
      self.__password = StringVar()
      self.__error = StringVar()
      self.master = master
      self.master.title('Login')
      userNameLabel = Label(self.master, text='UserID: ', bg=None, width=10).place(relx=0.300,rely=0.575)
      userNameEntry = Entry(self.master, textvariable=self.__username, width=25).place(relx=0.460,rely=0.575)
      userPasswordLabel = Label(self.master, text='Password: ', bg=None, width=10).place(relx=0.300,rely=0.625)
      userPasswordEntry = Entry(self.master, textvariable=self.__password, show='*', width=25).place(relx=0.460,rely=0.625)
      errorLabel = Label(self.master, textvariable=self.__error, bg=None, fg='red', width=35).place(relx=0.508,rely=0.545, anchor=CENTER)
      loginButton = Button(self.master, text='Login', command=self.login_user, bg='white', width=15).place(relx=0.300,rely=0.675)
      clearButton = Button(self.master, text='Clear', command=self.clear_entry, bg='white', width=15).place(relx=0.525,rely=0.675)
      self.master.bind('&lt;Return&gt;', lambda event: self.login_user()) #triggers the login subroutine if the enter key is pressed
  
    def login_user(self):
      username = self.__username.get()
      password = self.__password.get()
      hashPassword = (password.encode('utf-8'))
      newPass = hashlib.sha256()
      newPass.update(hashPassword)
      if username == '':
        self.__error.set('Error! No user ID entered')
      elif password == '':
        self.__error.set('Error! No password entered')
      else:
        with sqlite3.connect ('pkdata.db') as db:
          cursor = db.cursor()
          cursor.execute("select userID, password from users where userID=?",(username,))
          info = cursor.fetchone()
          if info is None:
            self.__error.set('Error! Login details not found!')
          else:
            dbUsername = info[0]
            dbPassword = info[1]
            if username == dbUsername or newPass.hexdigest() == dbPassword:
              self.open_main_menu()
              self.master.withdraw()
            else:
              self.__error.set('Error! please try again')
              self.clear_entry()
  
    def destroy(self):
      self.master.destroy()
  
    def clear_entry(self):
      self.__username.set('')
      self.__password.set('')
  
    def open_main_menu(self):
      root_main = Toplevel(self.master)
      root_main.state('zoomed')
      Main = main_menu(root_main)
      root_main.mainloop()
  
  
  class main_menu():
    def __init__(self, master):
      pass
  
  if __name__ == '__main__':
     main()
  </code></pre>