#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    21
    Rep Power
    0

    Browse button for tkinter


    Hello, I would like to add a browse button to one of my graphical interfaces, but lazy as I am I don't really want to program myself a browse button (you know the kind of button you use to open a file somewhere in your hard disk, if of course you are not a linux professional and open all your files with the terminal...)

    Is there such a button already built in Tkinter or do you know somewhere to find it, i did a little research and it doesn't seem that common...

    Thanks,
    erwin
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    At least you are honest about it

    The Browse button is just a button which launches the file or directory dialog. Nothing special

    This code...

    Code:
    Tkinter.Button(subframe, text = "Browse", command = self.loadtemplate, width = 10).pack()
    Code:
        def loadtemplate(self): 
            filename = tkFileDialog.askopenfilename(filetypes = (("Template files", "*.tplate")
                                                                 ,("HTML files", "*.html;*.htm")
                                                                 ,("All files", "*.*") ))
            if filename: 
                try: 
                    self.settings["template"].set(filename)
                except: 
                    tkMessageBox.showerror("Open Source File", "Failed to read file \n'%s'"%filename)
                    return
    This should show you the basic idea.

    grim
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    21
    Rep Power
    0
    100 % perfect! Thank Grim Archon!

    Just what I needed, the more it goes the more I am a fan of python!

IMN logo majestic logo threadwatch logo seochat tools logo