Python2.3 tkFileDialog.askopenfilename returns tuple on Cancel

Richard rshaw2 at midsouth.rr.com
Mon Aug 4 16:40:33 EDT 2003


timothy.williams at nvl.army.mil (Tim Williams) wrote in message news:<faf44c99.0308041102.ce7788e at posting.google.com>...
> I just installed Python 2.3 on my Redhat system. When I tried to run
> one of my programs that use tkFileDialog.askopenfilename(), I got an
> error because it returns a tuple instead of a null string when I
> select Cancel.
> 
> Python 2.2:
> 
> Python 2.2.2 (#3, Jan 21 2003, 08:39:06)
> [GCC 2.95.3 20010315 (release)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import tkFileDialog
> >>> f=tkFileDialog.askopenfilename()
> >>> print f
>  
> >>> f
>  ''
> >>> type(f)
> <type 'str'>
> 
> 
> Python 2.3:
> 
> Python 2.3 (#1, Aug  4 2003, 10:43:11)
> [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import tkFileDialog
> >>> f=tkFileDialog.askopenfilename()
> >>> f
>  ()
> >>> type(f)
> <type 'tuple'>
> 
> Both versions return a string when I select an actual file. Sometimes
> I want to click 'Cancel' when I want to bring up my GUI anyway and
> select the file later.
> 
> I got around this by just putting in an 
> 
> if not filename: filename='.'
> 
> after my call to askopenfilename().
> 
> Is this a bug or a feature?
> 
> Thanks.

I tried this under Windows 2000 and got a 'str' either way.

Richard




More information about the Python-list mailing list