title: Button Command with class in Python
body: <p>I'm trying to get this right but so far no luck. Would appreciate it if someone can help me with it.</p>
  
  <pre><code>import tkinter
  class MyGUI:
      def __init__(self):
          self.main_window = tkinter.Tk()
          self.button1 = tkinter.Button(self.main_window,text='Average',command=self.average)
          self.button1.pack()
          tkinter.mainloop()
      def average(self):
          self.mini_window = tkinter.Tk()
          self.avg_mess = tkinter.Label(self.mini_window,text='Results:')
          self.avg_result_var = tkinter.StringVar()
          self.avg_result_display = tkinter.Label(self.mini_window,textvariable=self.avg_result_var)
          self.avg_mess.pack()
          self.avg_result_display.pack()
          self.button2 = tkinter.Button(self.mini_window,text='Calculate',command=self.avg_calc)
          self.button2.pack()
      def avg_calc(self):
          self.avg_result = (100+300+80)/3
          self.avg_result_var.set(self.avg_result)
  gui = MyGUI()
  </code></pre>
  
  <p>The problem occurs when the <code>Calculate</code> button is clicked but the <code>avg_result_var</code> does not change its value. And hence the <code>avg.result_display</code> remains blank. I suspect there is something wrong with the function call when the button is pressed. I'm using Python 3.x. Thanks.</p>