tkFileDialog different between Linux and Windows

Tim Williams timothy.williams at nvl.army.mil
Tue Feb 24 12:55:38 EST 2004


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 first
upgraded from v2.2 to v2.3. I noticed that
tkFileDialog.askopenfilename() returns a tuple on Cancel instead of 
''. I found that the Windows version still returns a string (''). Now
I'm finding out that tkFileDialog.Directory().show() does this too.

>>> d1=tkFileDialog.Directory().show()
>>> d2=tkFileDialog.Directory().show()
>>> type(d1),type(d2)
(<type 'tuple'>, <type '_tkinter.Tcl_Obj'>)
>>> d2
<path object at 0x08295a48>
>>> d2
<path object at 0x08295a48>


d1 is the result of a Cancel, d2 is the result of a Ok.

>>> dir(d1)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__',
'__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__',
'__setattr__', '__str__']

>>> dir(d2)
['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__', '__unicode__', 'string',
'typename']


I thought this was a Tk8.3 vs Tk8.4 problem, so I put in a check:

        d = tkFileDialog.Directory().show()
        if TkVersion < 8.4:
            outdir=d
        else:
            outdir=d.string
        if d : self.setoutpath(outdir)

Then when I tried this on a Windows machine, it turns out that
tkFileDialog.Directory().show() still returns a string when TkVersion
is 8.4

How can I check tkFileDialog to do the "right" thing?  All I want is
the string that contains the path, but I want this to work on both
Linux and Windows.

Thanks.



More information about the Python-list mailing list