Tkinter:select directory dialog?
park997 at aol.comnotospam
Wed Sep 18 15:26:45 EDT 2002
Thanks this did the trick. I am still using
Python 2.0. The addition of askdirectory
to Python 2.2 was a good idea :-).
>> 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",
> if not directory:
> print "cancelled"
> print "selected", directory
><!-- (the eff-bot guide to) the python standard library:
More information about the Python-list