473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.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.
d1=tkFileDialog.Directory().show()
d2=tkFileDialog.Directory().show()
type(d1),type(d2) (<type 'tuple'>, <type '_tkinter.Tcl_Obj'>) d2 <path object at 0x08295a48> d2 <path object at 0x08295a48>
d1 is the result of a Cancel, d2 is the result of a Ok.
dir(d1) ['__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__']
dir(d2)

['__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.
Jul 18 '05 #1
2 2494
In article <fa**************************@posting.google.com >,
ti**************@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.
Jul 18 '05 #2
"Russell E. Owen" <no@spam.invalid> wrote in message news:<c1**********@nntp6.u.washington.edu>...
In article <fa**************************@posting.google.com >,
ti**************@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!
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim Williams | last post by:
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...
1
by: Mike Abel | last post by:
Hello i have a Linux Mandrake Distribution with Python 2.3 and Tcl/Tk 8.4. Python 2.2 and Tcl/Tk 8.3.3 returns an String if i made this: x = tkFileDialog.askdirectory(initialdir="was auch...
3
by: Tim Williams | last post by:
Hi. I'm using Python 2.3 and trying to use tkFileDialog to get a list of files. I get a message about the '-multiple' option is not a valid option in the call to Open. Python 2.3 (#1, Aug ...
2
by: Ringwraith | last post by:
Hello! I have the following problem. I use the tkFileDialog.askdirectory dialog to allow users of my application to pick some subfolder from 'C:/my_app' directory. I use initialdir='C:/my_app'...
2
by: Read Roberts | last post by:
I have the current Windows binary install of Python 2.3.4 on my Windows XP system. I am pained to discover that tkFileDialog.askdirectory() returns a mangled path when a directory is selected...
0
by: John Wheez | last post by:
Hi all, I'm using teh tkFileDialog to let teh user select a directory. We have long names which make it difficult to view the directories. For some reason the GUI windows doesn;t expand on...
4
by: mdmdmd | last post by:
Hello, I wish to collect 4 files from a user. So I have decided to use tkFileDialog askopenfilename. My problem is that after a few file selections the root window is destroyed (the whole...
0
by: Matthias Huening | last post by:
Hi, I have problems using tkFileDialog under Linux (Ubuntu 8.04 in my case, but other Linuxes seem to show the same behaviour). The following works fine: import tkFileDialog f =...
0
by: Leonhard Vogt | last post by:
Hello I have the following problem in Python 2.5 on Windows XP. On Ubuntu I do not see the problem. I have a Tkinter application as in the following example The entry-widget is somehow...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.