tkinter - tkFileDialog - how to get dir instead of file

Martin Franklin martin.franklin at
Wed Oct 31 10:42:27 CET 2001

Matthew Dixon Cowles wrote:

> On Mon, 29 Oct 2001 23:14:44 +0100, maxm <maxm at> wrote:
> Max,
>>I am writing my first tkinter program and so far it's been pretty
> That's great, you're ahead of the game.
>>But now I need to open a directory and not a file. I cannot see a
>>simple way to get this from the standard module "tkFileDialog".
>>Do I really have to write a special class for this?
> Alas, you probably do. Tk provides a directory chooser but Python
> doesn't (yet) expose it. I filed a feature request on SourceForge for
> it but it doesn't look like anything has been done about it yet,
> including by me.
> Regards,
> Matt

Or you could use this:-

from Tkinter import *

from tkCommonDialog import Dialog
class Chooser(Dialog):
    command = "tk_chooseDirectory"
    def _fixresult(self, widget, result):
        if result:
            self.options["initialdir"] = result = result # compatibility
        return result

def askdirectory(**options):
    return apply(Chooser, (), options).show()

More information about the Python-list mailing list