tkFileDialog different between Linux and Windows

T

Tim Williams

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.
<path object at 0x08295a48>


d1 is the result of a Cancel, d2 is the result of a Ok.
['__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__']
['__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.
 
R

Russell E. Owen

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. ....
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.

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.
 
T

Tim Williams

Russell E. Owen said:
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.


That did it! Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top