Problem with tkFileDialog.askdirectory(), Windows, and non-ascii paths

Tim Williams timothy.williams at
Fri Oct 8 14:06:02 CEST 2004

Read Roberts <rroberts at> wrote in message news:<mailman.4553.1097213592.5135.python-list at>...
> I have the current Windows binary install of Python 2.3.4 on my 
> Windows XP system.
> I am pained to discover that  tkFileDialog.askdirectory() returns  a 
> mangled path when a directory is selected which has non-ascii Unicode 
> path, as in Kanji characters, i.e. the usull "????" in place of the 
> original UTF-8 code points.  .
> After some time spent Google'ing. I don't find a discussion of this. 
> Is there some option  or configuration change I can make to fix this? 
> I can roll my own file-dialog , but I prefer to re-use code.

I had a problem with using tkFileDialog.filename between Windows and
Linux. The solution I got was to use unicode().

>>> In article <faf44c99.0402240955.4613fd6a at>,
>>>  timothy.williams at (Tim Williams) wrote:
>>> >I'm using Python 2.3.2 and tkFileDialog in a program I have. I'm
>>> >trying to use this on Linux (RH 8.0) and Windows 2000. When I
>>> >upgraded from v2.2 to v2.3. I noticed that
>>> >tkFileDialog.askopenfilename() returns a tuple on Cancel instead
>>> >''. I found that the Windows version still returns a string ('').
>>> >I'm finding out that tkFileDialog.Directory().show() does this
too. ...
>>> >How can I check tkFileDialog to do the "right" thing?  All I want
>>> >the string that contains the path, but I want this to work on
>>> >Linux and Windows.
>>> Is this the sort of thing you want?
>>> dirobj = tkFileDialog.askdirectory()
>>> if not dirobj:
>>>   # user Cancelled; works whether the return is '' or ()
>>>   return
>>> # dirobj may be a string or a Tk_Obj
>>> dirname = unicode(dirobj)
>>> The same code should work for askopenfilename.


More information about the Python-list mailing list