1

I got stuck.... Please help..

I am trying to display a file path that was selected in the text box in GUI. I managed to get the ode to display the actual content of the file.

    def OnButtonClick1(self):
        self.labelVariable.set( self.entryVariable.get())
        self.entry.focus_set()
        self.entry.selection_range(0, tkinter.END)
        filename = askopenfilename()
        with open(filename,'r') as f:
        for file in f:
            self.entry.insert(0,file)
            print(filename)

Please help me with getting it to display file path. Thanks

EDIT: def OnButtonClick1(self): self.labelVariable.set( self.entryVariable.get()) self.entry.focus_set() self.entry.selection_range(0, tkinter.END) filename = askopenfilename() with open(filename,'r') as f: for file in f: self.entry.insert(0,filename) print(filename)

Now this prints the filepath but more than one time?? Strange.. Please help :)

EDIT 2: I found the solution!!!!

   with open(filename,'r') as f:
       for file in f:
            data = f.read()
            self.entry.insert(0,filename)
            print(filename)

Happy DAYS!!!!

4

0 回答 0