Tkinter:select directory dialog?
fredrik at pythonware.com
Wed Sep 18 14:23:56 EDT 2002
Martin Franklin wrote:
> > A nice graphical "choose a directory" Dialog would help.
> > Does such a thing exist?
> from tkCommonDialog import Dialog
> class Chooser(Dialog):
> command = "tk_chooseDirectory"
> def _fixresult(self, widget, result):
> if result:
> self.options["initialdir"] = result
> self.directory = result # compatibility
> return result
> def askdirectory(**options):
> return apply(Chooser, (), options).show()
(hmm. I think I've seen that code before...)
the askdirectory function and a Directory class (same as
the Chooser above) was added to the tkFileDialog module
in Python 2.2:
from tkFileDialog import askdirectory
directory = askdirectory(
if not directory:
print "selected", directory
<!-- (the eff-bot guide to) the python standard library:
More information about the Python-list