This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tkinter - askopenfilenames returns string instead of tuple in windows 2.6.1 release
Type: behavior Stage:
Components: Tkinter Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Regression: Windows-tkinter-idle, unicode, and 0xxx filename
View: 19020
Assigned To: Nosy List: daku9999, dhalbert, ggenellina, gpolo, luckycusp, martinmiller, nosklo, pfhall, python-dev, serhiy.storchaka, som_veettil
Priority: normal Keywords:

Created on 2009-04-06 17:45 by daku9999, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue5712_workaround.py nosklo, 2010-01-29 19:23 workaround for the issue
python_issue_5712.py martinmiller, 2013-12-10 18:24 Source code used to supply requested values.
Messages (18)
msg85658 - (view) Author: daku9999 (daku9999) Date: 2009-04-06 17:45
from tkFileDialog import askopenfilenames

a = askopenfilenames()
print a
print type(a)

'''
--output--
J:/PortablePython_1.1_py2.6.1/Aatest26/tk_new/rgb2hex.py
J:/PortablePython_1.1_py2.6.1/Aatest26/tk_new/bluebtn.jpg
J:/PortablePython_1.1_py2.6.1/Aatest26/tk_new/redbtn.jpg
<type 'unicode'>
'''

---- behaviour seen on windows xp 2.6.1 python release.  Linux
distributions seem fine.
---- parsing above string (as it's not a tuple anymore) is difficult as
it is a list of filenames separated by a space but spaces can be in the
middle of filenames.
msg91291 - (view) Author: Gabriel Genellina (ggenellina) Date: 2009-08-05 01:11
With 2.6.2 on Windows, I get filenames surrounded by {}, all in a 
single unicode string.
The change may be related to the new Tk library used, not directly the 
tkFileDialog module.

(BTW, I don't see *any* unit tests for tkinter :( )
msg91297 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-08-05 02:29
> With 2.6.2 on Windows, I get filenames surrounded by {}, all in a
> single unicode string.

This string surrounded by { } indicates it is supposed to be a tcl
list, which didn't get converted but should be done by tkFileDialog.

> The change may be related to the new Tk library used, not directly the
> tkFileDialog module.
>

It could be, or not. A simple solution would be to call the splitlist
function from _tkinter on that string, which tkFileDialog should be
doing indifferently of expecting objects from _tkinter or not.

> (BTW, I don't see *any* unit tests for tkinter :( )
>

There are some one a separated branch for now, but it doesn't include
tkFileDialog yet.
msg98530 - (view) Author: Clovis Fabricio (nosklo) * Date: 2010-01-29 19:23
I've written a quick workaround for the issue, where I manually split the filenames and always return a tuple.

It might be useful to someone experiencing this problem, so I'm adding it to the issue here.
msg107932 - (view) Author: vijay (luckycusp) Date: 2010-06-16 16:02
Two issues related with the workaround suggested by nosklo.

1. Splitting the filepaths isnt simple, as there may be blank spaces etc.
2. We have different versions of Python installed in our Lab machines, some have 2.5 and others got 2.6. If I run the code using the version2.6 workaround on a machine with version2.5, obviously it gives an error!!

Any updates on a fix? This bug is really giving me a hard time.
msg107935 - (view) Author: vijay (luckycusp) Date: 2010-06-16 16:46
Update!! I found a very good workaround for this and it works very nicely, with both 2.5 and 2.6 versions. 

Below is the segment from my code:-

from Tkinter import *
import tkFileDialog

master = Tk()
master.withdraw() #hiding tkinter window

Inputfiles = tkFileDialog.askopenfilenames(title="Select the source input file(s)", filetypes=[("mpf file",".mpf"),("All files",".*")])

#Heres the TRICK!
InputfilesList =  master.tk.splitlist(Inputfiles)
msg107947 - (view) Author: Clovis Fabricio (nosklo) * Date: 2010-06-16 18:49
UGH! Sorry for that, I mispasted something and didn't notice, since it filled the comment entry box perfectly :(

This is the real message I meant to paste:

----------------------------

vijay,

The workaround I provided above takes the blank spaces in filepaths
you mention into account and splits the paths correctly in all
situations I can think of. I'm using it in production now for over an
year, and had no issues at all. Perhaps you can provide an example of
path that would break the code, so it can be fixed.

thanks in advance
Clovis
msg107952 - (view) Author: vijay (luckycusp) Date: 2010-06-16 19:45
Hi Clovis

Ok, I did not check if your split string function check for spaces or not, sorry for that. 

In my first post I mentioned this:-

"2. We have different versions of Python installed in our Lab machines, some have 2.5 and others got 2.6. If I run the code using the version2.6 workaround on a machine with version2.5, obviously it gives an error!!"

Infact I started out using your split string function but it was on a machine with Python2.6. It worked fine. Then I ran the same code on a machine with version Python2.5 and it threw an error when I tried calling your function, because the argument I passed to your function was already a tuple and not a string!! (I hope I could explain without confusing)

I would prefer my code to have some level of downward compatibility (to be able to run on Python of lower versions). Thats the reason I prefer to use the 'splitlist' method from Tkinter, as I dont need to change my code for different Python versions.

Best Regards
Vijay
msg120740 - (view) Author: Peter Hall (pfhall) Date: 2010-11-08 13:37
There seems some similarity between this issue and issue #10316 which occurs on Linux.
msg197765 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-09-15 12:41
Is it still reproducible on 2.7?
msg205809 - (view) Author: Martin Miller (martinmiller) Date: 2013-12-10 12:59
Answering Serhiy Storchaka's question: Yes it's still reproducible with 2.7.6.
msg205816 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-12-10 14:37
What are values of Tkinter.wantobjects, Tkinter._support_default_root, Tkinter._default_root, Tkinter._default_root.wantobjects()? Before and after calling tkFileDialog.askopenfilenames().
msg205840 - (view) Author: Martin Miller (martinmiller) Date: 2013-12-10 18:24
Requested information:

Before                                              
Tkinter.wantobjects: 1                              
Tkinter._support_default_root: 1                    
Tkinter._default_root: None                         
Tkinter._default_root has no attribute 'wantobjects'

After                                               
Tkinter.wantobjects: 1                              
Tkinter._support_default_root: 1                    
Tkinter._default_root: .                            
Tkinter._default_root.wantobjects(): True
msg210781 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-09 19:32
Thank you Martin.

May be this issue was fixed in issue19020.
msg222149 - (view) Author: Som Veettil (som_veettil) Date: 2014-07-03 05:12
i had similar issue with python 2.7.. works fine with fix provided by vijay (luckycusp)
msg107935 - (view) - http://bugs.python.org/msg107935

thanks a lot.
msg222304 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-07-04 18:40
Som, what is full version of your Python?
msg222569 - (view) Author: Som Veettil (som_veettil) Date: 2014-07-08 17:19
@Serhiy Storchaka - its Python 2.7.6
msg222573 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-07-08 18:08
This bug was fixed in 2.7.7.
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49962
2014-07-08 18:08:10serhiy.storchakasetstatus: open -> closed
superseder: Regression: Windows-tkinter-idle, unicode, and 0xxx filename
resolution: duplicate
messages: + msg222573
2014-07-08 17:19:51som_veettilsetmessages: + msg222569
2014-07-04 18:40:28serhiy.storchakasetmessages: + msg222304
2014-07-03 05:12:42som_veettilsetnosy: + som_veettil
messages: + msg222149
2014-02-09 19:32:49serhiy.storchakasetmessages: + msg210781
2013-12-10 18:24:30martinmillersetfiles: + python_issue_5712.py

messages: + msg205840
2013-12-10 14:37:26serhiy.storchakasetmessages: + msg205816
2013-12-10 12:59:17martinmillersetnosy: + martinmiller
messages: + msg205809
2013-10-13 17:59:53georg.brandllinkissue8010 superseder
2013-09-15 12:41:15serhiy.storchakasetnosy: + serhiy.storchaka

messages: + msg197765
versions: - Python 2.6
2013-03-21 02:14:47r.david.murraysetmessages: - msg184831
2013-03-21 02:13:44python-devsetnosy: + python-dev
messages: + msg184831
2010-11-08 13:37:21pfhallsetnosy: + pfhall
messages: + msg120740
2010-06-16 19:45:03luckycuspsetmessages: + msg107952
2010-06-16 19:33:15eric.araujosetmessages: - msg107946
2010-06-16 18:49:29nosklosetmessages: + msg107947
2010-06-16 18:45:57nosklosetmessages: + msg107946
2010-06-16 16:46:33luckycuspsetmessages: + msg107935
2010-06-16 16:02:31luckycuspsetnosy: + luckycusp
messages: + msg107932
2010-04-03 02:37:45nosklosetversions: + Python 2.7
2010-03-11 19:38:09dhalbertsetnosy: + dhalbert
2010-01-29 19:23:42nosklosetfiles: + issue5712_workaround.py
nosy: + nosklo
messages: + msg98530

2009-08-05 02:29:58gpolosetmessages: + msg91297
2009-08-05 01:11:27ggenellinasetnosy: + ggenellina
messages: + msg91291
2009-08-03 18:33:23gpolosetnosy: + gpolo
2009-04-06 17:45:10daku9999create