inserting path in the entry box in Python GUI
Question: I'm new to GUI programming. I made a small GUI where the user browses the file
and then do the functionalities he wants with the file.

Now i have an Entry Box in the GUI and whenever a user browses for the
required file and after he finishes browsing the path to the file should
appear in the entry box.

basically i want it like this befor browsing![before
browsing](http://i.stack.imgur.com/lomHa.png) after browsing ![after
browsing](http://i.stack.imgur.com/wFrWV.png)

How can i do this?

My code to the GUI is :

    
    
    #!/usr/bin/python
    import Tkinter as tk
    from tkFileDialog   import *
    import os
    class StageGui:
        prot=0
        log=0
        cwd=os.getcwd()
        def __init__(self,parent,tex):
            self.tex=tex
            self.fm=tk.Frame(remodelmain)
            self.l1=tk.Label(self.fm, text='Import .prot File').grid(row=0,column=0,sticky='w',padx=5,pady=10)
            self.l2=tk.Label(self.fm, text='Import .log File').grid(row=1,column=0,sticky='w',padx=5,pady=10)
            self.protentry = tk.Entry(self.fm, width = 50).grid(row=0,column=1,sticky='w',padx=5,pady=10)
            self.logentry = tk.Entry(self.fm, width = 50).grid(row=1,column=1,sticky='w',padx=5,pady=10)
            self.b1=tk.Button(self.fm, text='Browse',height=1,width=20,command=self.callback).grid(row=0,column=2,sticky='e',padx=5,pady=10)
            self.b2=tk.Button(self.fm, text='Browse',height=1,width=20,command=self.callback1).grid(row=1,column=2,sticky='e',padx=5,pady=10)
            self.fm.pack()
            self.fm0=tk.Frame(remodelmain,width=500,height=500)
            self.b3=tk.Button(self.fm0, text='Check',height=1,width=15,command=self.check).grid(row=4,column=2,sticky='e',padx=5,pady=10)
            self.b4=tk.Button(self.fm0, text='Inertia',height=1,width=15).grid(row=5,column=2,sticky='e',padx=5,pady=10)
            self.b5=tk.Button(self.fm0, text='Summary',height=1,width=15).grid(row=6,column=2,sticky='e',padx=5,pady=10)
            self.b6=tk.Button(self.fm0, text='Report',height=1,width=15).grid(row=7,column=2,sticky='e',padx=5,pady=10)
            self.fm0.pack(side='right')
            self.fm1=tk.Frame(remodelmain,width=200,height=200)
            self.tex1= tk.Text(self.fm1,width=130,height=10)
            self.l3=tk.Label(self.fm1, text='Status Box:').grid(row=6,column=0,sticky='nw')
            self.tex1.grid(row=6,column=1,sticky='s',padx=20,pady=10)
            self.fm1.pack(side='left',anchor='w')
        def callback(self):
            name= askopenfilename()
            StageGui.prot=name
            self.printstatements(StageGui.prot)
        def printstatements(self,name):
            self.tex1.insert('end','\nthe file has been imported \n')
            s='the path of the imported file is {}\n'.format(name)
            self.tex1.insert('end',s)
            self.tex1.see(tk.END)
            return
        def callback1(self):
            name1= askopenfilename()
            StageGui.log=name1
            self.printstatements(StageGui.log)
        def check(self):
            file=open(StageGui.prot,'r')
            a,b,c='|Checks|','|Status|','|Remarks|'
            mess='\n{0:10s} \t {1:10s} \t {2:100s}\n'.format(a,b,c)
            self.tex.insert('end',mess)
            count_string_occurance(file)
    
    remodelmain = tk.Tk()
    fmn1=tk.Frame(remodelmain,width=300,height=300)
    l3=tk.Label(fmn1, text='Message Box:').grid(row=6,column=0,sticky='nw')
    tex= tk.Text(fmn1,width=130,height=60)
    tex.grid(row=6,column=1,sticky='s',padx=20,pady=20)
    fmn1.pack(side='bottom',anchor='w')
    stagegui=StageGui(remodelmain,tex)
    remodelmain.title('prototype_remodel')
    remodelmain.geometry('1200x1200+300+300')
    remodelmain.mainloop()
    


Answer: Create a string varible that is associated with the Entry widget:

    
    
    self.pathVar = tk.StringVar(self.fm)
    self.protentry = tk.Entry(self.fm, width = 50, textvariable=self.pathVar).grid(row=0,column=1,sticky='w',padx=5,pady=10)
    

Then after getting the path, set the variable to that path:

    
    
    name= askopenfilename()
    self.pathVar.set(name)
    

