title: how do i get the result from a tk dialogbox to put value back into the form?
body: <p>Having problems trying to populate a tk form widget</p>
  
  <p>Its a simple question really, and I am a bit loathed to post it here because there must be a really simple explanation, but i cant see it right now.</p>
  
  <p>I am new to python. I have a python3 program to perform some tasks on an excel file.  The program uses three files.  All i need is a simple interface, which allows the user to select the scriptfile (file1), procedures file (file2) and there will be an third output file. Then use these files to do the main processing.</p>
  
  <p>I have copied the code from some websites, and mangled some together to come up with something (see below).  However, I cant see how i am supposed to write back the code into the text widget.</p>
  
  <p>for example, i would expect something in the form of 
  Window.t_out = "new value"
  or self.t_out = "new value"</p>
  
  <p>However, i cant see how to access t_out for example.
  it could be i have created more confusion using a class, but i thought this was the preferred way.</p>
  
  <p>Known issues: 
  1.  I have .grid and .place and dont intend to mix the two, but just trying to see which is better
  2. Im not entirely sure at this point if I am supposed to keep the button functions with the class or outside of the class, since both seem to work.</p>
  
  <pre><code>
  class Window(Frame):
  
      def __init__(self, master=None):
          # parameters that you want to send through the Frame class.
          Frame.__init__(self, master)
  
          # reference to the master widget, which is the tk window
          self.master = master
  
          # with that, we want to then run init_window, which doesn't yet exist
          self.init_window()
  
  
      # Creation of init_window
      def init_window(self):
  
          self.master.title("Select Files to process")    # changing the title of our master widget
         # self.pack(fill=BOTH, expand=1)                  # allowing the widget to take the full space of the root window
  
          TROW = 1
          SROW = 2
          PROW = 4
          COL = 2
          COLBTN = 30
  
          # Define Menu
  
          menu = Menu(self.master)                        # creating a menu instance
          self.master.config(menu=menu)
  
          file = Menu(menu)                               # create the file Menu
  
          file.add_command(label="Exit",                  # adds a Exit to the menu option
                           command=self.menu_exit)        # bind client_exit to run on event
  
          menu.add_cascade(label="File", menu=file)       # bind the function file to Menu "File" Label
  
          edit = Menu(menu)                               # create the Edit Menu
          edit.add_command(label="Undo",
                           command=self.menu_undo)        # adds a command Undo to Edit menu
  
          menu.add_cascade(label="Edit", menu=edit)       # bind the function edit to Menu "Edit" Label
  
          # Define Form
  
          # Define the Labels
  
          Label(self.master, text="File1").grid(row=SROW)
          Label(self.master, text="File2").grid(row=PROW)
  
          # Define the Widgets
  
          t_out = Text(self.master,  height=15, width =100)
          t_scr = Text(self.master,  height =1, width =90)
          t_proc = Text(self.master,  height =1, width =90)
          t4 = Text(self.master,  height=10, width=20)
  
          # Define the positioning
          t_out.grid(row=TROW, column=COL)
          t_scr.grid(row=SROW, column=COL, sticky = W)
          t_proc.grid(row=PROW, column=COL, sticky = W)
          t4.place (x=50,y=320)
  
  
          # Assign the widgets to procedures
          Button(self.master, text='script',
                 command=get_script_file).grid(row=SROW, column=COLBTN, sticky=W, pady=4)
          Button(self.master, text='procedure',
                 command=get_procedure_file).grid(row=PROW, column=COLBTN, sticky=W, pady=4)
          Button(self.master, text='getVAL',
                 command=self.getval).place(x=320,y=310)
  
  
      def getval(self):
          from tkinter import filedialog
          filename = filedialog.askopenfilename(initialdir="/", title="Select file",
                                                     filetypes=(("Excel Files", "*.xlsx"), ("all files", "*.*")))
           # I NEED TO WRITE BACK THE FILENAME INTO THE TEXT WIDGET HERE
  
  
      def menu_exit(self):
          exit()
  
      def menu_undo(self):
          print ("Undo not implemented yet")
  
  
  def get_script_file():
      from tkinter import filedialog
      root.filename = filedialog.askopenfilename(initialdir="/", title="Select file",
                                                 filetypes=(("Excel Files", "*.xlsx"), ("all files", "*.*")))
      print("got ", root.filename)
           # I NEED TO WRITE BACK THE FILENAME INTO THE TEXT WIDGET HERE ALSO
  
  def get_procedure_file():
      print ("Not implemented yet")
  
  
  # root window created. Here, that would be the only window, but
  # you can later have windows within windows.
  root = Tk()
  root.geometry("1000x400")
  
  # creation of an instance
  app = Window(root)
  
  # mainloop
  root.mainloop()
  </code></pre>