473,569 Members | 2,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
d1=tkFileDialog .Directory().sh ow()
d2=tkFileDialog .Directory().sh ow()
type(d1),type(d 2) (<type 'tuple'>, <type '_tkinter.Tcl_O bj'>) 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.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.
Jul 18 '05 #1
2 2502
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.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. ....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.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 .
Jul 18 '05 #2
"Russell E. Owen" <no@spam.invali d> wrote in message news:<c1******* ***@nntp6.u.was hington.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.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.

...
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.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 .

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
2836
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 when I select Cancel. Python 2.2: Python 2.2.2 (#3, Jan 21 2003, 08:39:06) on linux2 Type "help", "copyright", "credits" or "license" for...
1
4561
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 immer", title="xxx") print type(x) <type 'str'>
3
3773
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 4 2003, 10:43:11) on linux2 Type "help", "copyright", "credits" or "license" for more information.
2
2914
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' option to set 'C:/my_app' as initial directory. But I want my initial directory to be also a root directory, so the user cannot pick any directory...
2
4258
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 which has non-ascii Unicode path, as in Kanji characters, i.e. the usull "????" in place of the original UTF-8 code points. . After some time...
0
932
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 Windows like it does on OS X or Linux. Is there a method to make the widths of the tkFileDialog windows larger when using Windows XP?
4
2109
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 program just dissappears) I have created a simple example and was able to reproduce the same thing with this. I've just started using tkinter so I...
0
1173
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 = tkFileDialog.askopenfilename()
0
1493
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 blocked (i cannot type characters into it) when I call askopenfilename before I create the widget. Calling askopenfile again (by clicking the button)...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.