I'm using Windows XP with Python 2.7.2 & Tkinter GUI kit. I want to build a simple GUI that has a text field and "Browse" button that will select a file through directories such as C:\ (Just like Windows Explorer). That file selected will be displayed in the text field in the GUI. Hope this is descriptive enough.
I have something else that might help you:
    ## {{{ http://code.activestate.com/recipes/438123/ (r1)
    # ======== Select a directory:
    import Tkinter, tkFileDialog
    root = Tkinter.Tk()
    dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')
    if len(dirname ) > 0:
        print "You chose %s" % dirname 
    # ======== Select a file for opening:
    import Tkinter,tkFileDialog
    root = Tkinter.Tk()
    file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file')
    if file != None:
        data = file.read()
        file.close()
        print "I got %d bytes from this file." % len(data)
    # ======== "Save as" dialog:
    import Tkinter,tkFileDialog
    myFormats = [
        ('Windows Bitmap','*.bmp'),
        ('Portable Network Graphics','*.png'),
        ('JPEG / JFIF','*.jpg'),
        ('CompuServer GIF','*.gif'),
        ]
    root = Tkinter.Tk()
    fileName = tkFileDialog.asksaveasfilename(parent=root,filetypes=myFormats ,title="Save the image as...")
    if len(fileName ) > 0:
        print "Now saving under %s" % nomFichier
    ## end of http://code.activestate.com/recipes/438123/ }}}
Here is the website that I got it from: http://code.activestate.com/recipes/438123-file-tkinter-dialogs/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With