blob: 593ad8fd9d1d9445d6b45296b86c2f5a06209f25 [file] [log] [blame]
Fredrik Lundh4ecd7132001-10-29 22:58:55 +00001#
2# tkDirectoryChooser.py
3# $Id$
4#
5# tk common directory dialogue
6#
7# this module provides interfaces to the native directory dialogue
8# available in Tk 8.3 and newer.
9#
10# written by Fredrik Lundh, November 2000.
11#
12
13#
14# options (all have default values):
15#
16# - initialdir: initial directory. preserved by dialog instance.
17#
18# - mustexist: if true, user must pick an existing directory
19#
20# - parent: which window to place the dialog on top of
21#
22# - title: dialog title
23#
24
25from tkCommonDialog import Dialog
26
27class Chooser(Dialog):
28
29 command = "tk_chooseDirectory"
30
31 def _fixresult(self, widget, result):
32 if result:
33 # keep directory until next time
34 self.options["initialdir"] = result
35 self.directory = result # compatibility
36 return result
37
38#
39# convenience stuff
40
41def askdirectory(**options):
42 "Ask for a directory name"
43
44 return apply(Chooser, (), options).show()
45
46# --------------------------------------------------------------------
47# test stuff
48
49if __name__ == "__main__":
50
51 print "directory", askdirectory()
52