title: Tkinter - Open one window and close another
body: <p>I want to have a login screen and when the login is successful, the screen is closed and a new screen is created. The problem is , when I do just like the following code , both screens opens at the same time. If you have any suggestions to improve the code , please do! :)</p>
  
  <pre><code>from Tkinter import *
  import mysql.connector
  import tkMessageBox
  
  class Tela_login(Frame):
      root = Tk()
      root.geometry("1024x768")
      root.resizable(width=FALSE, height=FALSE)
      background_image = PhotoImage(file="fundo.gif")
      def __init__(self,master):
          Frame.__init__(self,master)
          self.grid()
          fundo = Label(image=self.background_image)
          fundo.place(x=0,y=0,relwidth=1,relheight=1)
          self.create_screen()
  
      def create_screen(self):
          self.label1 = Label(text="Login",font = ("Arial",60))
          self.label2 = Label(text="Senha",font = ("Arial",60))
          self.login = Entry(font = ("Arial",60),width = 10)
          self.senha = Entry(show="*",font = ("Arial",60), width= 10)
          self.entrar = Button(text="Entrar",command=lambda : self.efetua_login(),font = ("Arial",60),width=10)
  
          self.label1.grid(padx=258,pady=(70,0))
          self.login.grid(padx=258)
          self.label2.grid(padx=258,pady=(50,0))
          self.senha.grid(padx=258)
          self.entrar.grid(padx=258,pady=(50,0))
  
      def efetua_login(self):
          login = self.login.get()
          senha = self.senha.get()
  
          cnx = mysql.connector.connect(user='root', password='123qwe', host='192.168.56.1', database='teste')
          cursor = cnx
          cursor = cnx.cursor()
  
          query = ("SELECT nome, senha FROM funcionario WHERE nome = %s AND senha = %s")
          cursor.execute(query, (login,senha))
          row = cursor.fetchone()
  
          if row is None:
  
              tkMessageBox.showinfo("Erro","Usuario ou Senha Incorretos")
  
          else:
              app2 = Tela_principal()
              self.root.destroy()
              Tela_principal.root.mainloop()
  
  
  class Tela_principal(Frame):
      root = Tk()
      root.geometry = ("1024x768")
      root.resizable(width=FALSE, height=FALSE)
  
      def inicia(self, master):
          background_image = PhotoImage(file="fundo.gif")
          app2 = Tela_principal(self.root)
          Frame.__init__(self, master)
          self.grid()
          self.create_widgets()
  
  app = Tela_login(Tela_login.root)
  Tela_login.root.mainloop()
  </code></pre>