title: Creating a Python and Tkinter Login System
body: <p>I have written this code for login and registration...
  But here I had first created different window popups for each action; Now I feel there should be only one window and all other popups to not appear...{I mean I wish to perform all this code in just one window but I'm unable to do it....}</p>
  <p><em><strong>I want to replace windows so that the whole process takes place in only 1 WINDOW; please help!</strong></em></p>
  <p>Thanks!</p>
  <pre><code>#import modules
  
  from tkinter import *
  import os
  
  # Designing window for registration
  
  def register():
      global register_screen
      register_screen = Toplevel(main_screen)
      register_screen.title(&quot;Register&quot;)
      register_screen.geometry(&quot;300x250&quot;)
  
      global username
      global password
      global username_entry
      global password_entry
      username = StringVar()
      password = StringVar()
  
      Label(register_screen, text=&quot;Please enter details below&quot;, bg=&quot;blue&quot;).pack()
      Label(register_screen, text=&quot;&quot;).pack()
      username_lable = Label(register_screen, text=&quot;Username * &quot;)
      username_lable.pack()
      username_entry = Entry(register_screen, textvariable=username)
      username_entry.pack()
      password_lable = Label(register_screen, text=&quot;Password * &quot;)
      password_lable.pack()
      password_entry = Entry(register_screen, textvariable=password, show='*')
      password_entry.pack()
      Label(register_screen, text=&quot;&quot;).pack()
      Button(register_screen, text=&quot;Register&quot;, width=10, height=1, bg=&quot;blue&quot;, command = 
  register_user).pack()
  
  
  # Designing window for login 
  
  def login():
      global login_screen
      login_screen = Toplevel(main_screen)
      login_screen.title(&quot;Login&quot;)
      login_screen.geometry(&quot;300x250&quot;)
      Label(login_screen, text=&quot;Please enter details below to login&quot;).pack()
      Label(login_screen, text=&quot;&quot;).pack()
  
      global username_verify
      global password_verify
  
      username_verify = StringVar()
      password_verify = StringVar()
  
      global username_login_entry
      global password_login_entry
  
      Label(login_screen, text=&quot;Username * &quot;).pack()
      username_login_entry = Entry(login_screen, textvariable=username_verify)
      username_login_entry.pack()
      Label(login_screen, text=&quot;&quot;).pack()
      Label(login_screen, text=&quot;Password * &quot;).pack()
      password_login_entry = Entry(login_screen, textvariable=password_verify, show= '*')
      password_login_entry.pack()
      Label(login_screen, text=&quot;&quot;).pack()
      Button(login_screen, text=&quot;Login&quot;, width=10, height=1, command = login_verify).pack()
  
  # Implementing event on register button
  
  def register_user():
  
      username_info = username.get()
      password_info = password.get()
  
      file = open(username_info, &quot;w&quot;)
      file.write(username_info + &quot;\n&quot;)
      file.write(password_info)
      file.close()
  
      username_entry.delete(0, END)
      password_entry.delete(0, END)
  
      Label(register_screen, text=&quot;Registration Success&quot;, fg=&quot;green&quot;, font=(&quot;calibri&quot;, 11)).pack()
  
  # Implementing event on login button 
  
  def login_verify():
      username1 = username_verify.get()
      password1 = password_verify.get()
      username_login_entry.delete(0, END)
      password_login_entry.delete(0, END)
  
      list_of_files = os.listdir()
      if username1 in list_of_files:
          file1 = open(username1, &quot;r&quot;)
          verify = file1.read().splitlines()
          if password1 in verify:
              login_sucess()
  
          else:
              password_not_recognised()
  
      else:
          user_not_found()
  
  # Designing popup for login success
  
  def login_sucess():
      global login_success_screen
      login_success_screen = Toplevel(login_screen)
      login_success_screen.title(&quot;Success&quot;)
      login_success_screen.geometry(&quot;150x100&quot;)
      Label(login_success_screen, text=&quot;Login Success&quot;).pack()
      Button(login_success_screen, text=&quot;OK&quot;, command=delete_login_success).pack()
  
  # Designing popup for login invalid password
  
  def password_not_recognised():
      global password_not_recog_screen
      password_not_recog_screen = Toplevel(login_screen)
      password_not_recog_screen.title(&quot;Success&quot;)
      password_not_recog_screen.geometry(&quot;150x100&quot;)
      Label(password_not_recog_screen, text=&quot;Invalid Password &quot;).pack()
      Button(password_not_recog_screen, text=&quot;OK&quot;, command=delete_password_not_recognised).pack()
  
  # Designing popup for user not found
  
  def user_not_found():
      global user_not_found_screen
      user_not_found_screen = Toplevel(login_screen)
      user_not_found_screen.title(&quot;Success&quot;)
      user_not_found_screen.geometry(&quot;150x100&quot;)
      Label(user_not_found_screen, text=&quot;User Not Found&quot;).pack()
      Button(user_not_found_screen, text=&quot;OK&quot;, command=delete_user_not_found_screen).pack()
  
  # Deleting popups
  
  def delete_login_success():
      login_success_screen.destroy()
  
  
  
  
  def delete_password_not_recognised():
      password_not_recog_screen.destroy()
  
  
  def delete_user_not_found_screen():
      user_not_found_screen.destroy()
  
  
  # Designing Main(first) window
  
  def main_account_screen():
      global main_screen
      main_screen = Tk()
      main_screen.geometry(&quot;300x250&quot;)
      main_screen.title(&quot;Account Login&quot;)
      Label(text=&quot;Select Your Choice&quot;, bg=&quot;blue&quot;, width=&quot;300&quot;, height=&quot;2&quot;, font=(&quot;Calibri&quot;, 13)).pack()
      Label(text=&quot;&quot;).pack()
      Button(text=&quot;Login&quot;, height=&quot;2&quot;, width=&quot;30&quot;, command = login).pack()
      Label(text=&quot;&quot;).pack()
      Button(text=&quot;Register&quot;, height=&quot;2&quot;, width=&quot;30&quot;, command=register).pack()
  
      main_screen.mainloop()
  
  
  main_account_screen()
  </code></pre>