title: Returning a selected value from a dynamically populated combobox as a global variable?
body: <p>I'm trying to automate some work to process data that is brought in from SQL. Towards the start of my full code I found and altered the below class from elsewhere on the site to act as a smooth interface so others can use the code too. </p>
  
  <p>The aim of this is to retrieve the desired 'MPAN' and a year from the options. The combo-boxes are populated exactly as I wished, however the problem comes when trying to retrieve the selected values as global variables, and close the GUI when clicking 'Submit', as it stands nothing happens and the values are not obtained, but there is no error produced.</p>
  
  <p>My assumption would be I've made a mistake with my 'getMPAN' function, though I am not very experienced with this level of tkinter so would greatly apprciate a hand. For simplicity sake I have added the category dictionary to act as mock data.</p>
  
  <pre><code>b2=[[2018],[2019],[2020],[2021],[2022],[2023],[2024],[2025]]
  category = {'home': ['utilities','rent','cable'],
      'car': ['gas','oil','repairs'],
      'rv':['parks','maintenance','payment']}
  params=''
  mpan=''
  year=''
  
  class Application(Frame):
  
      def __init__(self, master=None, Frame=None):
          Frame.__init__(self, master)
          super(Application,self).__init__()
          self.grid(column = 5,row = 20,padx = 50,pady = 50)
          self.createWidgets()
  
      def getUpdateData(self,  event):
          self.AccountCombo['values'] = category[self.CategoryCombo.get()]
          self.AccountCombo.current(0)
  
      def createWidgets(self):
          tk.Label(text = 'Area Code:').grid(row = 2,column = 1,padx = 10)
          tk.Label(text = 'MPAN:').grid(row = 4,column = 1,padx = 10)
          tk.Label(text = 'Year:').grid(row = 6, column = 1, padx = 10)
          self.AccountCombo = ttk.Combobox( width = 15)
          self.AccountCombo.grid(row = 5,column = 1,pady = 25,padx = 10)
  
          self.CategoryCombo = ttk.Combobox(width = 15,  values = list(category.keys()))
          self.CategoryCombo.bind('&lt;&lt;ComboboxSelected&gt;&gt;', self.getUpdateData)
          self.CategoryCombo.grid(row = 3,column = 1,padx = 10,pady = 25)
  
          self.YearCombo = ttk.Combobox(width = 15, values = b2)
          self.YearCombo.grid(row = 7, column = 1, padx = 10, pady = 25)
          self.YearCombo.current(0)
  
      def getMPAN(self):
          mpan=self.AccountCombo.get()
          year=self.YearCombo.get()
          self.destroy()
  
          global params
          params=[mpan,year]
  
  w=tk.Button(Application(), text='Submit', command=Application().getMPAN)
  w.grid(row=8, column=1)
  
  app = Application()
  app.master.title('MPAN Selector')
  app.mainloop()
  </code></pre>
  
  <p>This is my first time posting on the site so I apologise if I'm missing any details. I've seen similar questions but none with solutions for this situation.</p>