title: Python tkinter passing input value within the same class
body: <p>Most of the code below is just so the problem is accurately replicated, the issue most likely is in the hand-off of <code>filename</code> from<code>askopenfilenameI()</code> to <code>printing(stringToPrint)</code>or the <code>if</code> statement at the end.</p>
  <h2>Goal</h2>
  <p>The goal of this program is to simply print the file path to the console when <code>Print File Path</code> button is clicked.</p>
  <h2>Current state</h2>
  <p>When the program is executed the window appears correctly and the it lets you select a file in the file system. Once the file is opened, the script seems to call <code>printing</code> method before it executes its own <code>print</code> statement. When I open another file it prints the only the print statement from <code>askopenfilename()</code> (which is correct).</p>
  <p>However, clicking the <code>Print File Path</code> Button does not seem to get work at any stage.</p>
  <p>An example output would be:</p>
  <p>Value on click: <code>no-file</code></p>
  <p>askopenfilename value: <code>C:/Temp/AFTER_FIRST_OPEN.txt</code></p>
  <p>askopenfilename value: <code>C:/Temp/AFTER_SECOND_OPEN.txt</code></p>
  <h2>Code</h2>
  <pre><code>import Tkinter, Tkconstants, tkFileDialog
  
  filename = 'no-file'
  
  class TkApp(Tkinter.Frame):
  
      def __init__(self, root):
  
          Tkinter.Frame.__init__(self, root)
      
          # options for buttons
          button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5}
      
          # define buttons
          Tkinter.Button(self, text='Open File', command=self.askopenfilename).pack(**button_opt)
          Tkinter.Button(self, text='Print File Path', command=self.printing(filename)).pack(**button_opt)
          Tkinter.Button(self, text='Quit', command=self.quit).pack(**button_opt)
           
          # define options for opening or saving a file
          self.file_opt = options = {}
          options['defaultextension'] = '.twb'
          options['filetypes'] = [('All', '*')]
          options['initialdir'] = 'C:\\'
          options['parent'] = root
          options['title'] = 'Select a File'
  
      def askopenfilename(self):
          &quot;&quot;&quot;Returns an opened file in read mode.
          This time the dialog just returns a filename and the file is opened by your own code.
          &quot;&quot;&quot;
          global filename        
          # get filename
          filename = tkFileDialog.askopenfilename(**self.file_opt)
      
          # open file on your own
          if filename:
              print &quot;askopenfilename value: &quot; + filename
              return filename
              
      def printing(self, stringToPrint):
          print &quot;Value on click: &quot; + stringToPrint
     
      def quit(self):
          root.destroy()
          
   if __name__=='__main__':
          root = Tkinter.Tk()
          root.title(&quot;Path Printer&quot;)  
          TkApp(root).pack()
          root.mainloop()
          
  </code></pre>