Tkinter:select directory dialog?

Fredrik Lundh 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(
        title="select directory",
        mustexist=1
    )

    if not directory:
        print "cancelled"
    else:
        print "selected", directory

</F>

<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list