tkFileDialog different between Linux and Windows

Tim Williams timothy.williams at nvl.army.mil
Thu Feb 26 08:14:13 EST 2004


"Russell E. Owen" <no at spam.invalid> wrote in message news:<c1gqa2$mve$1 at nntp6.u.washington.edu>...
> In article <faf44c99.0402240955.4613fd6a at posting.google.com>,
>  timothy.williams at nvl.army.mil (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 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.


That did it! Thanks!



More information about the Python-list mailing list