June 22nd, 2004, 11:47 AM
-
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
June 23rd, 2004, 05:13 AM
-
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
June 23rd, 2004, 09:01 AM
-
100 % perfect! Thank Grim Archon!
Just what I needed, the more it goes the more I am a fan of python!