Python2.3 tkFileDialog.askopenfilename returns tuple on Cancel

Discussion in 'Python' started by Tim Williams, Aug 4, 2003.

  1. Tim Williams

    Tim Williams Guest

    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.
     
    Tim Williams, Aug 4, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xavier
    Replies:
    0
    Views:
    427
    Xavier
    Aug 6, 2003
  2. Sonia Rovner

    tkFileDialog.askopenfilename

    Sonia Rovner, Mar 4, 2004, in forum: Python
    Replies:
    4
    Views:
    12,116
    Sonia Rovner
    Mar 5, 2004
  3. Justin Straube
    Replies:
    2
    Views:
    1,179
  4. Replies:
    3
    Views:
    485
  5. Hamilton, William

    RE: tkFileDialog.askopenfilename()

    Hamilton, William, May 16, 2007, in forum: Python
    Replies:
    1
    Views:
    362
Loading...

Share This Page