title: switch frame with tkinter
body: <p>I use following code:</p>
  
  <p><a href="https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter">Switch between two frames in tkinter</a></p>
  
  <pre><code>import RPi.GPIO as GPIO
  from threading import Timer,Thread,Event
  
  import tkinter as tk                # python 3
  from tkinter import font  as tkfont # python 3
  #import Tkinter as tk     # python 2
  #import tkFont as tkfont  # python 2
  
  #----------------------------------------------------------
  #Setup GPIO
  #----------------------------------------------------------
  GPIO.setwarnings(False)
  # RPi.GPIO Layout verwenden (wie Pin-Nummern)
  #GPIO.setmode(GPIO.BOARD)
  GPIO.setmode(GPIO.BCM)
  
  # (GPIO 17,27,22,5) auf Input setzen
  chan_list1 = [17, 27, 22, 5]
  GPIO.setup(chan_list1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  
  # (GPIO 12,13,23,24) auf Output setzen
  chan_list = [12, 13, 23, 24]
  GPIO.setup(chan_list, GPIO.OUT)
  #----------------------------------------------------------
  
  #--------------------------------------------------------
  #Timer
  #--------------------------------------------------------
  class perpetualTimer():
  
     def __init__(self,t,hFunction):
        self.t=t
        self.hFunction = hFunction
        self.thread = Timer(self.t,self.handle_function)
  
     def handle_function(self):
        self.hFunction()
        self.thread = Timer(self.t,self.handle_function)
        self.thread.start()
  
     def start(self):
        self.thread.start()
  
     def cancel(self):
        self.thread.cancel()
  #--------------------------------------------------------
  
  
  
  class SampleApp(tk.Tk):
  
      def __init__(self, *args, **kwargs):
          tk.Tk.__init__(self, *args, **kwargs)
  
          self.overrideredirect(1)              #Remove Title bar  
          self.geometry("480x272")              #Set the window dimensions
  
          self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
  
          # the container is where we'll stack a bunch of frames
          # on top of each other, then the one we want visible
          # will be raised above the others
          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):
              page_name = F.__name__
              frame = F(parent=container, controller=self)
              self.frames[page_name] = frame
  
              # put all of the pages in the same location;
              # the one on the top of the stacking order
              # will be the one that is visible.
              frame.grid(row=0, column=0, sticky="nsew")
  
          self.show_frame("StartPage")
  
      def show_frame(self, page_name):
          '''Show a frame for the given page name'''
          frame = self.frames[page_name]
          frame.tkraise()
  
  
  class StartPage(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          label = tk.Label(self, text="This is the start page", font=controller.title_font)
          label.pack(side="top", fill="x", pady=10)
  
          button1 = tk.Button(self, text="Go to Page One",
                              command=lambda: controller.show_frame("PageOne"))
          button2 = tk.Button(self, text="Go to Page Two",
                              command=lambda: controller.show_frame("PageTwo"))
          button1.pack()
          button2.pack()
  
  
  class PageOne(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          label = tk.Label(self, text="This is page 1", font=controller.title_font)
          label.pack(side="top", fill="x", pady=10)
          button = tk.Button(self, text="Go to the start page",
                             command=lambda: controller.show_frame("StartPage"))
          button.pack()
  
  
  class PageTwo(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          label = tk.Label(self, text="This is page 2", font=controller.title_font)
          label.pack(side="top", fill="x", pady=10)
          button = tk.Button(self, text="Go to the start page",
                             command=lambda: controller.show_frame("StartPage"))
          button.pack()
  
  
  
  def printer():
      print ('PIT(!)')
      SampleApp.show_frame('PageOne') 
  if __name__ == "__main__":
      t = perpetualTimer(0.01,printer)
      t.start()
  
      app = SampleApp()
      app.mainloop()
  </code></pre>
  
  <p>Is it possible to switch the frames without using buttons?
  e.g. comparing a counter. if the counter value is 1 show page 1
  if counter value is 2 show page 2 and so on.</p>
  
  <p>If I'm honest, I do not remember exactly what I've all tried.
  One thing I tried was "controller.show_frame("StartPage")" from def printer sub.
  What I want to achieve is to switch the pages from the "def printer" sub,
  which is called periodically.
  I do not know if that's possible?</p>