title: Making a login page using tkinter in python
body: <p>I'm trying to load a new frame when the user presses the login button as long as the details entered are correct. I've included <code>print</code> commands within the <code>LogInCheck</code> function in order to see if the code is executing correctly, which it is. My only problem is that it wont change the frame. I get the error <code>'LogIn' object missing attribute 'show_frame'</code>   </p>
  
  <pre><code>from tkinter import *
  from tkinter import ttk
  
  import tkinter as tk
  
  LARGE_FONT= ("Arial", 16)
  SMALL_FONT= ("Arial", 12)
  current_tariff = None
  
  
  def tariff_A():
      global current_tariff
      current_tariff= "A"
  
  def tariff_B():
      global current_tariff
      current_tariff= "B"
  
  def tariff_C():
      global current_tariff
      current_tariff= "C"
  
  
  class PhoneCompany(tk.Tk):
  
      def __init__(self, *args, **kwargs):
  
          tk.Tk.__init__(self, *args, **kwargs)
          container = tk.Frame(self)
  
          container.pack(side="top", fill="both", expand = True)
  
          container.grid_rowconfigure(0, weight=1)
          container.grid_columnconfigure(0, weight=1)
  
          self.frames = {}
  
          for F in (StartPage, PageOne, PageTwo, PageThree, PageFour, PageFive, LogIn):
  
              frame = F(container, self)
  
              self.frames[F] = frame
  
              frame.grid(row=0, column=0, sticky="nsew")
  
          self.show_frame(LogIn)
  
      def show_frame(self, cont):
  
          frame = self.frames[cont]
          frame.tkraise()
  </code></pre>
  
  <p>Thats my main class and this is the login page class:</p>
  
  <pre><code> class LogIn(tk.Frame):
  
      def LogInCheck(self):
          global actEntry
          global pinEntry
  
          act = "james"
          pin = "Python123"
  
          actNum = actEntry.get()
          pinNum = pinEntry.get()
  
          print("FUNCTION RUN")
          if actNum == act and pinNum == pin:
              print("CORRECT")
              self.show_frame(StartPage)
          elif actNum != act or pinNum != pin: 
              print("INCORRECT")
              self.show_frame(LogIn)
  
      def __init__(self, parent, controller):
  
          global actEntry
          global pinEntry
          self.controller = controller
  
          tk.Frame.__init__(self, parent)
  
          logLabel = ttk.Label(self, text = "Login With Your Username and 
  Password", font = LARGE_FONT)
          logLabel.pack(side = TOP, anchor = N, expand = YES)
  
  
          actLabel = Label(self, text = 'Username:')
          actEntry = Entry(self)
  
          pinLabel = Label(self, text = 'Password: ')
          pinEntry = Entry(self, show ="*")
  
          actLabel.pack(pady =10, padx = 10, side = TOP, anchor = N)
          pinLabel.pack(pady =5, padx = 10, side = TOP, anchor  = S)
  
          actEntry.pack(pady =10, padx = 10, side = TOP, anchor = N)
          pinEntry.pack(pady =5, padx = 10, side = TOP, anchor  = S)
  
          logInButton = tk.Button(self, text = "Login",
                               command = self.LogInCheck)
          logInButton.pack(side = TOP, anchor = S)
  
          quitButton = tk.Button(self, text = "Quit", command = quit)
          quitButton.pack(side = BOTTOM, anchor = S)
  
  
  if __name__ == "__main__":
      app = PhoneCompany()
      app.mainloop()
  </code></pre>
  
  <p>I'll include my full code if you need to look at the rest of it: </p>
  
  <pre><code>from tkinter import *
  from tkinter import ttk
  
  import tkinter as tk
  
  LARGE_FONT= ("Arial", 16)
  SMALL_FONT= ("Arial", 12)
  current_tariff = None
  
  
  def tariff_A():
      global current_tariff
      current_tariff= "A"
  
  def tariff_B():
      global current_tariff
      current_tariff= "B"
  
  def tariff_C():
      global current_tariff
      current_tariff= "C"
  
  
  class PhoneCompany(tk.Tk):
  
      def __init__(self, *args, **kwargs):
  
          tk.Tk.__init__(self, *args, **kwargs)
          container = tk.Frame(self)
  
          container.pack(side="top", fill="both", expand = True)
  
          container.grid_rowconfigure(0, weight=1)
          container.grid_columnconfigure(0, weight=1)
  
          self.frames = {}
  
          for F in (StartPage, PageOne, PageTwo, PageThree, PageFour, PageFive, LogIn):
  
              frame = F(container, self)
  
              self.frames[F] = frame
  
              frame.grid(row=0, column=0, sticky="nsew")
  
          self.show_frame(LogIn)
  
      def show_frame(self, cont):
  
          frame = self.frames[cont]
          frame.tkraise()
  
  
  class StartPage(tk.Frame):
  
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self,parent)
          label = tk.Label(self, text="MENU", font=LARGE_FONT)
          label.pack(pady=10,padx=10)
  
          button = tk.Button(self, text="View Account Balance",
                              command=lambda: controller.show_frame(PageOne))
          button.pack()
  
          button2 = tk.Button(self, text="Display Current Tariff",
                              command=lambda: controller.show_frame(PageTwo))
          button2.pack()
  
          button3 = tk.Button(self, text="View List of Rates",
                             command=lambda: controller.show_frame(PageThree))
          button3.pack()
  
          button4 = tk.Button(self, text="View Latest Bill",
                              command=lambda: controller.show_frame(PageFour))
          button4.pack()
  
  
  class PageOne(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          label = tk.Label(self, text="Account Balance", font=LARGE_FONT)
          label.pack(pady=10,padx=10)
  
          sublabel = tk.Label(self, text="Your current account balance is £230", font=SMALL_FONT)
          sublabel.pack(pady=10,padx=10)
  
          button1 = tk.Button(self, text="Back to Menu",
                             command=lambda: controller.show_frame(StartPage))
          button1.pack()
  
  class PageTwo(tk.Frame):
  
      def __init__(self, parent, controller):
          global current_tariff
          tk.Frame.__init__(self, parent)
          label = tk.Label(self, text="Current Tariff", font=LARGE_FONT)
          label.pack(pady=10,padx=10)
  
          sublabel = tk.Label(self, text="Your current tariff is "+str(current_tariff), font=SMALL_FONT)
          sublabel.pack(pady=10,padx=10)
  
          button1 = tk.Button(self, text="Change Tariff",
                              command=lambda: controller.show_frame(PageFive))
          button1.pack()
  
          button2 = tk.Button(self, text="Back to Home",
                             command=lambda: controller.show_frame(StartPage))
          button2.pack()
  
  class PageThree(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          label = tk.Label(self, text="Tariff Rates", font=LARGE_FONT)
          label.pack(pady=10,padx=10)
  
          sublabel = tk.Label(self, text="Peak Rates: A: £0.30 | B: £0.10 | C: £0.90", anchor="w", font=SMALL_FONT)
          sublabel.pack(pady=10,padx=10)
  
          sublabel2 = tk.Label(self, text="Off Peak: A: £0.05 | B: £0.02 | C: -", anchor="w", font=SMALL_FONT)
          sublabel2.pack(pady=10,padx=10)
  
          sublabel3 = tk.Label(self, text="Line Rental: A: £15.00 | B: £20.00 | C: £30.00", anchor="w", font=SMALL_FONT)
          sublabel3.pack(pady=10,padx=10)
  
          button1 = tk.Button(self, text="Back to Home",
                             command=lambda: controller.show_frame(StartPage))
          button1.pack()
  
  class PageFour(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          label = tk.Label(self, text="Latest Bill", font=LARGE_FONT)
          label.pack(pady=10,padx=10)
  
          button1 = tk.Button(self, text="Back to Home",
                             command=lambda: controller.show_frame(StartPage))
          button1.pack()
  
  class PageFive(tk.Frame):
  
      def __init__(self, parent, controller):
          global current_tariff
          tk.Frame.__init__(self, parent)
          label = tk.Label(self, text="Change Tariff", font=LARGE_FONT)
          label.pack(pady=10,padx=10)
  
          sublabel = tk.Label(self, text="Select new tariff\nView list of tariff rates on the main menu to see the prices.", font=SMALL_FONT)
          sublabel.pack(pady=10,padx=10)
  
          button1 = tk.Button(self, text="A",
                              command=lambda:[controller.show_frame(StartPage),tariff_A])
          button1.pack()
  
          button2 = tk.Button(self, text="B",
                              command=lambda:[controller.show_frame(StartPage),tariff_B])
          button2.pack()
  
          button3 = tk.Button(self, text="C",
                              command=lambda:[controller.show_frame(StartPage),tariff_C])
          button3.pack()
  
          button4 = tk.Button(self, text="Back to Home",
                              command=lambda: controller.show_frame(StartPage))
          button4.pack()
  
  class LogIn(tk.Frame):
  
      def LogInCheck(self):
          global actEntry
          global pinEntry
  
          act = "james"
          pin = "Python123"
  
          actNum = actEntry.get()
          pinNum = pinEntry.get()
  
          print("FUNCTION RUN")
          if actNum == act and pinNum == pin:
              print("CORRECT")
              self.show_frame(StartPage)
          elif actNum != act or pinNum != pin: 
              print("INCORRECT")
              self.show_frame(LogIn)
  
      def __init__(self, parent, controller):
  
          global actEntry
          global pinEntry
          self.controller = controller
  
          tk.Frame.__init__(self, parent)
  
          logLabel = ttk.Label(self, text = "Login With Your Username and Password", font = LARGE_FONT)
          logLabel.pack(side = TOP, anchor = N, expand = YES)
  
  
          actLabel = Label(self, text = 'Username:')
          actEntry = Entry(self)
  
          pinLabel = Label(self, text = 'Password: ')
          pinEntry = Entry(self, show ="*")
  
          actLabel.pack(pady =10, padx = 10, side = TOP, anchor = N)
          pinLabel.pack(pady =5, padx = 10, side = TOP, anchor  = S)
  
          actEntry.pack(pady =10, padx = 10, side = TOP, anchor = N)
          pinEntry.pack(pady =5, padx = 10, side = TOP, anchor  = S)
  
          #  runs the 'LoginCheck' function
  
          logInButton = tk.Button(self, text = "Login",
                                   command = self.LogInCheck)
          logInButton.pack(side = TOP, anchor = S)
  
          quitButton = tk.Button(self, text = "Quit", command = quit)
          quitButton.pack(side = BOTTOM, anchor = S)
  
  
  if __name__ == "__main__":
      app = PhoneCompany()
      app.mainloop()
  </code></pre>
  
  <p>I know it's quite messy and there may be other errors, but for now i just need to figure out why it wont change the frame after successfully logging in.</p>