title: Getting value from radiobox in Tkinter - Python
body: <p>I'm trying to create a GUI in Python using the Tkinter module, and part of that involves giving the user the option of two radioboxes, and to select which one they want. Depending on which box they tick, it then runs different functions which return different results - results that I then want to use outside of the window class. But I don't know how to send a value from inside the class to outside the class; I'm sure its fairly simple but I can't for the life of me work it out. </p>
  
  <p>My current code is:</p>
  
  <pre><code>class BatchIndiv():
  def __init__(self, master):
      self.master=master
      self.startwindow()
      self.b=0
  
  def startwindow(self):
  
      self.var1 = IntVar()
      self.textvar = StringVar()
  
      self.Label1=Label(self.master, text="Batch or indivdual import?")
      self.Label1.grid(row=0, column=0)
  
      self.Label2=Label(self.master, textvariable=self.textvar)
      self.Label2.grid(row=2, column=0)
  
      self.rb1 = Radiobutton(self.master, text="Batch", variable=self.var1,
                             value=1, command=self.cb1select)
      self.rb1.grid(row=1, column=0, sticky=W)
  
      self.rb2 = Radiobutton(self.master, text="Individual", variable=self.var1,
                             value=2, command=self.cb1select)
      self.rb2.grid(row=1, column=1, sticky=W)
  
      self.Button1=Button(self.master, text="ok", command=self.ButtonClick)
      self.Button1.grid(row=1, column=2)
  
  def ButtonClick(self):
       if (self.var1.get())==1:
          b=BatchImport()
          return b
          self.master.quit()
          self.master.destroy()
       elif (self.var1.get())==2:
          b=IndivImport()
          return b
          self.master.quit()
          self.master.destroy()
       else: pass
  
  def cb1select(self):
      return self.var1.get()
  
  #End of class definition.
  #Code:
  
  root=Tk()
  window=BatchIndiv(root)
  b=BatchIndiv.ButtonClick.b
  root.mainloop()
  
  ....
  </code></pre>
  
  <p>Treat the BatchImport and IndivImport functions as black boxes, they just return an integer value, which I assign to the variable b inside ButtonClick(). I need that value to do some stuff below root.mainloop(), (i.e. where .... is), but I don't know how to get it. Tkinter is really quite irritating, especially as everyone has different methods of doing things so the online documentation is never the same - tried doing what was written in various ones and it just gave me more lovely error messages. </p>
  
  <p>Any and all help would be appreciated.</p>
  
  <p>PS - how can I make the window close when the button is pressed, and still send the value b back to the rest of the code, and not just quit python completely? As you can see I tried using .quit() and .destroy() but to no luck. </p>