tkFileDialog, but no tkDirectoryDialog?

Kevin Cazabon kcazabon at home.com
Wed Nov 1 15:33:39 EST 2000


Just a side note:  I believe that the tk_choosedirectory command is only
valid in TK 8.4 and above... correct?

Kevin.


"Fredrik Lundh" <fredrik at effbot.org> wrote in message
news:TTZL5.3874$jv2.437438 at newsc.telia.net...
| vplatt at my-deja.com wrote:
| > I have been unable to find any Tkinter dialog
| > which would allow users of my application to pick
| > a directory.  My work-around right now is to
| > simply allow them to choose a file (using
| > tkFileDialog) within the directory, which I then
| > split from the result and get the directory name
| > that way.
|
| so let's write one:
|
| #
| # 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()
|
| </F>
|
|





More information about the Python-list mailing list