faqts : Computers : Programming : Languages : Python : Tkinter

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 20 people (80%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Is there a dialog to choose a directory?

Nov 6th, 2002 22:55
John Withers, Greg Goodman, Daniel Haertle, Andrew Brown,


There is since Python 2.2, see Lib/Lib-tk/tkFileDialog.py
You can look at the details at
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=478654&group_id=5470
There is nothing I know of for earlier versions, unfortunately. I
checked  the python-list, but there are only unsuccessful requests.
---
Tk 8.3 has a directory chooser that you can invoke from Tkinter.
Running Python 1.5.2 with Tkinter (tk_version 8.3): 
$ python
Python 1.5.2 (#1, Mar  3 2001, 01:35:43)  [GCC 2.96 20000731 (Red Hat
Linux 7.1 2 on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from Tkinter import *
>>> root = Tk()
>>> root.tk.eval('set tk_version')
'8.3'
>>> root.tk.eval('::tk::dialog::file::chooseDir::tkChooseDirectory')
'/usr/Tools/Tcl/Stuff'
The Tcl module containing the tkChooseDirectory proc is choosedir.tcl in
the tk8.3 library directory.
---
The following code will work for you. I have no idea if it is avialable
prior to 2.2 of Py, but is definitely only available in Tk 8.3+
>from tkFileDialog import *
>
>print askdirectory()