title: Python/tkinter: Pressing OK in dialog destroys the info in it
body: <p>I'm using Python/tkinter for a GUI and I found a strange behaviour.</p>
  <p>I'm building a very small dialog for selecting the language for my app. Then when closing it, I find that my 'result' variable in the dialog is gone.</p>
  <p>Here's the snippet:</p>
  <pre><code>import tkinter as tk
  from tkinter.simpledialog import Dialog
  from tkinter import ttk, LEFT, ACTIVE
  from tkinter.ttk import Button, Frame
  
  class LanguageDialog(Dialog):
      lang_dict = {
          'italiano': 'it',
          'español': 'es',
          'english': 'en',
          'galego': 'gl',
      }
  
      def __init__(self, parent, *args, **kwargs):
          super().__init__(parent, *args, **kwargs)
          self.selected_language = tk.StringVar()
          self.result = 'en'  # default value
  
      def _on_cmb_change(self, event):
          &quot;&quot;&quot;
              Keeps updated the result variable with the code I want in the end
          &quot;&quot;&quot;
          print(self.lang_dict[self.selected_language.get()])
          self.result = self.lang_dict[self.selected_language.get()]
  
      def body(self, master):
          self.selected_language = tk.StringVar()
          ops = tuple(self.lang_dict.keys())
          cmb_lang = ttk.Combobox(self, values=ops, state='readonly',
                                  textvariable=self.selected_language)
          cmb_lang.pack(side=tk.TOP)
  
          cmb_lang.bind('&lt;&lt;ComboboxSelected&gt;&gt;', self._on_cmb_change)
  
      def buttonbox(self):
          &quot;&quot;&quot;add standard button box.
  
          override if you do not want the standard buttons
          &quot;&quot;&quot;
  
          box = Frame(self)
  
          w = Button(box, text=&quot;OK&quot;, width=10, command=self.ok, default=ACTIVE)
          w.pack(side=LEFT, padx=5, pady=5)
  
          self.bind(&quot;&lt;Return&gt;&quot;, self.ok)
  
          box.pack()
  
  if __name__ == '__main__':
      root = tk.Tk()
      d = LanguageDialog(root)
      print(f'After the dialog, {d.result}')
      root.mainloop()
  </code></pre>
  <p>I believe I have some misconception on how to use the dialog. While debugging I saw the dialog triggers some destroy() method, but it seems like it is probably coming again to the initializer and executing the</p>
  <pre><code>self.result = 'en'
  </code></pre>
  <p>line, even though I didn't create or invoke the dialog again through LanguageDialog().</p>
  <p>I searched the web for similar examples and found that they are using the dialog in the same way, for example, <a href="https://code-maven.com/slides/python/tk-customized-simple-dialog" rel="nofollow noreferrer">here</a></p>