title: How to implement listener using tkinter?
body: <p>I am trying to develop a dialog box to be used with tkinter that has an entry box and a button.  I want to be able to enter a value in the entry box and have the entered value "returned" when the dialog is destroyed.  The following code works, but does not perform as I've described.  There are two buttons on the gui. The first launches the dialog box and the second retrieves the entered value.  I wish to eliminate the second button and have a listener activate the getValues method when the "Save Input" button in the dialog is pressed.  Here is the code:</p>
  
  <pre><code>from tkinter import *
  
  class myDialog():
      def __init__(self):
          self.t = Toplevel()
          self.t.title("Sample")
          self.answer = None
          self.v1 = StringVar()
          self.e1 = Entry(self.t, textvariable=self.v1)
          self.e1.focus()
          self.e1.pack()
          self.saveButton = Button(self.t, text="Save Input", command=self.buttonPressed)
          self.saveButton.pack()
  
      def buttonPressed(self):
          print("Popup Button Pressed")
          self.answer = self.e1.get()
          self.t.destroy()
  
  class myTk(Tk):
      def __init__(self):
          Tk.__init__(self)
          self.button = Button(text="Display Dialog", command = self.displayPopButton)
          self.button.pack()
          self.getButton = Button(text="Print Values", command=self.getValues)
          self.getButton.pack()
  
      def displayPopButton(self):
          self.b1 = myDialog()
  
      def getValues(self):
          print(self.b1.answer)
  
  myTk().mainloop()
  </code></pre>