tkFileDialog different between Linux and Windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Williams

    tkFileDialog different between Linux and Windows

    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.as kopenfilename() returns a tuple on Cancel instead of
    ''. I found that the Windows version still returns a string (''). Now
    I'm finding out that tkFileDialog.Di rectory().show( ) does this too.
    [color=blue][color=green][color=darkred]
    >>> d1=tkFileDialog .Directory().sh ow()
    >>> d2=tkFileDialog .Directory().sh ow()
    >>> type(d1),type(d 2)[/color][/color][/color]
    (<type 'tuple'>, <type '_tkinter.Tcl_O bj'>)[color=blue][color=green][color=darkred]
    >>> d2[/color][/color][/color]
    <path object at 0x08295a48>[color=blue][color=green][color=darkred]
    >>> d2[/color][/color][/color]
    <path object at 0x08295a48>


    d1 is the result of a Cancel, d2 is the result of a Ok.
    [color=blue][color=green][color=darkred]
    >>> dir(d1)[/color][/color][/color]
    ['__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__']
    [color=blue][color=green][color=darkred]
    >>> dir(d2)[/color][/color][/color]
    ['__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.Di rectory().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.Di rectory().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.
  • Russell E. Owen

    #2
    Re: tkFileDialog different between Linux and Windows

    In article <faf44c99.04022 40955.4613fd6a@ posting.google. com>,
    timothy.william s@nvl.army.mil (Tim Williams) wrote:
    [color=blue]
    >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.a skopenfilename( ) returns a tuple on Cancel instead of
    >''. I found that the Windows version still returns a string (''). Now
    >I'm finding out that tkFileDialog.Di rectory().show( ) does this too.[/color]
    ....[color=blue]
    >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.[/color]

    Is this the sort of thing you want?

    dirobj = tkFileDialog.as kdirectory()
    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 .

    Comment

    • Tim Williams

      #3
      Re: tkFileDialog different between Linux and Windows

      "Russell E. Owen" <no@spam.invali d> wrote in message news:<c1gqa2$mv e$1@nntp6.u.was hington.edu>...[color=blue]
      > In article <faf44c99.04022 40955.4613fd6a@ posting.google. com>,
      > timothy.william s@nvl.army.mil (Tim Williams) wrote:
      >[color=green]
      > >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.a skopenfilename( ) returns a tuple on Cancel instead of
      > >''. I found that the Windows version still returns a string (''). Now
      > >I'm finding out that tkFileDialog.Di rectory().show( ) does this too.[/color]
      > ...[color=green]
      > >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.[/color]
      >
      > Is this the sort of thing you want?
      >
      > dirobj = tkFileDialog.as kdirectory()
      > 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 .[/color]


      That did it! Thanks!

      Comment

      Working...