title: Adding to a counter on each frame for a quiz in python tkinter?
body: <p>So I've simplified my code down to the basics to try and get this to work. The mainpage, which you press 'play' on takes you to the page 'MathsQ1', this is the first question. The page has a question and four button, one of them being the right button. I've been able to make two different commands for the right and wrong buttons, that take you to the next question. But also I want the right function to add 1 to a counter which is called 'correct'. Once you finish the last question, it will take you the page 'MathsEnd' which will then display your score as "congrats you got (correct)/2" and I would really appreciate it if someone told me what I'm doing wrong. Thanks.</p>
  
  <p>The code:</p>
  
  <pre><code>import tkinter as tk
  from tkinter import ttk
  
  #INITIALIZING
  class MegaQuiz(tk.Tk):
  
      def __init__(self, *args, **kwargs):
          tk.Tk.__init__(self, *args, **kwargs)
  
          tk.Tk.wm_title(self, "THE MEGA POP QUIZ")
          self.geometry("930x2000")
          self.highlightbackground="#FF846B"
  
          self.correct = 0
  
          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 (MainPage, MathsQ1, MathsQ2, MathsEnd):
              page_name = F.__name__
              frame = F(parent=container, controller=self)
              self.frames[page_name] = frame
              frame.grid(row=0, column=0, sticky="nsew")
  
          self.show_frame("MainPage")
  
      def show_frame(self, page_name):
          frame = self.frames[page_name]
          frame.tkraise()
  
  class MainPage(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          self.configure(background="#FFC2B5")
  
  
          #Play BUTTON
          tk.Button(self, text="PLAY", width=10, 
                          command = lambda: controller.show_frame("MathsQ1")) .grid(column=1, row=11, columnspan=8, pady=20, sticky="nesw")
  
  class MathsQ1(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          self.configure(background="#FFC2B5")
  
          tk.Label(self, text="Maths Quiz") .grid(column=2, row=0)
  
          tk.Label(self, text="Question 1") .grid(column=4, row=1, columnspan=5, sticky="nesw")
  
          tk.Button(self, text="wrong",
                    command=self.wrong) .grid(column=4, row=3, sticky="nesw")
          tk.Button(self, text="right",
                    command=self.right) .grid(column=4, row=5, sticky="nesw")
          tk.Button(self, text="wrong",
                    command=self.wrong) .grid(column=6, row=3, sticky="nesw")
          tk.Button(self, text="wrong",
                    command=self.wrong) .grid(column=6, row=5, sticky="nesw")
  
      def wrong(self):
          self.controller.show_frame("MathsQ2")
  
      def right(self):
          self.controller.show_frame("MathsQ2")
  
          self.controller.correct = self.controller.correct + 1
  
  class MathsQ2(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          self.configure(background="#FFC2B5")
  
          tk.Label(self, text="Maths Quiz") .grid(column=2, row=0)
  
          tk.Label(self, text="Question 2") .grid(column=4, row=1, columnspan=5, sticky="nesw")
  
          tk.Button(self, text="wrong",
                    command=self.wrong) .grid(column=4, row=3, sticky="nesw")
          tk.Button(self, text="right",
                    command=self.right) .grid(column=4, row=5, sticky="nesw")
          tk.Button(self, text="wrong",
                    command=self.wrong) .grid(column=6, row=3, sticky="nesw")
          tk.Button(self, text="wrong",
                    command=self.wrong) .grid(column=6, row=5, sticky="nesw")
  
      def wrong(self):
          self.controller.show_frame("MathsEnd")
  
      def right(self):
          self.controller.show_frame("MathsEnd")
  
          self.controller.correct = self.controller.correct + 1
  
  class MathsEnd(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          self.configure(background="#FFC2B5")
  
          tk.Label(self, text=("congrats you got " + str(self.controller.correct) + "/2")) .grid(column=1, row=1)
  
          tk.Button(self, text="Back To Home",
                              command = lambda: controller.show_frame("MainPage")) .grid(column=6, row=10, sticky="nesw", pady=10)
  
  
  #RUNNING PROGRAM
  app = MegaQuiz()
  
  app.mainloop()
  </code></pre>