summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-10-29 22:58:55 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2001-10-29 22:58:55 (GMT)
commit4ecd71376c3828dc86217d5cf433959960db7329 (patch)
treec547289a858fae9205a8a99a4e16af20c676f0b0 /Lib
parenta427a2b8d09a756119d424efac85159a0270b503 (diff)
downloadcpython-4ecd71376c3828dc86217d5cf433959960db7329.zip
cpython-4ecd71376c3828dc86217d5cf433959960db7329.tar.gz
cpython-4ecd71376c3828dc86217d5cf433959960db7329.tar.bz2
directory chooser (requires a recent version of Tk)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/lib-tk/tkDirectoryChooser.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/Lib/lib-tk/tkDirectoryChooser.py b/Lib/lib-tk/tkDirectoryChooser.py
new file mode 100644
index 0000000..593ad8f
--- /dev/null
+++ b/Lib/lib-tk/tkDirectoryChooser.py
@@ -0,0 +1,52 @@
+#
+# tkDirectoryChooser.py
+# $Id$
+#
+# tk common directory dialogue
+#
+# this module provides interfaces to the native directory dialogue
+# available in Tk 8.3 and newer.
+#
+# written by Fredrik Lundh, November 2000.
+#
+
+#
+# options (all have default values):
+#
+# - initialdir: initial directory. preserved by dialog instance.
+#
+# - mustexist: if true, user must pick an existing directory
+#
+# - parent: which window to place the dialog on top of
+#
+# - title: dialog title
+#
+
+from tkCommonDialog import Dialog
+
+class Chooser(Dialog):
+
+ command = "tk_chooseDirectory"
+
+ def _fixresult(self, widget, result):
+ if result:
+ # keep directory until next time
+ self.options["initialdir"] = result
+ self.directory = result # compatibility
+ return result
+
+#
+# convenience stuff
+
+def askdirectory(**options):
+ "Ask for a directory name"
+
+ return apply(Chooser, (), options).show()
+
+# --------------------------------------------------------------------
+# test stuff
+
+if __name__ == "__main__":
+
+ print "directory", askdirectory()
+