Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tkinter - askopenfilenames returns string instead of tuple in windows 2.6.1 release #49962

Closed
daku9999 mannequin opened this issue Apr 6, 2009 · 18 comments
Closed

tkinter - askopenfilenames returns string instead of tuple in windows 2.6.1 release #49962

daku9999 mannequin opened this issue Apr 6, 2009 · 18 comments
Labels
topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@daku9999
Copy link
Mannequin

daku9999 mannequin commented Apr 6, 2009

BPO 5712
Nosy @dhalbert, @serhiy-storchaka
Superseder
  • bpo-19020: Regression: Windows-tkinter-idle, unicode, and 0xxx filename
  • Files
  • issue5712_workaround.py: workaround for the issue
  • python_issue_5712.py: Source code used to supply requested values.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-07-08.18:08:10.835>
    created_at = <Date 2009-04-06.17:45:10.789>
    labels = ['type-bug', 'expert-tkinter']
    title = 'tkinter - askopenfilenames returns string instead of tuple in windows 2.6.1 release'
    updated_at = <Date 2014-07-08.18:08:10.833>
    user = 'https://bugs.python.org/daku9999'

    bugs.python.org fields:

    activity = <Date 2014-07-08.18:08:10.833>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-07-08.18:08:10.835>
    closer = 'serhiy.storchaka'
    components = ['Tkinter']
    creation = <Date 2009-04-06.17:45:10.789>
    creator = 'daku9999'
    dependencies = []
    files = ['16041', '33083']
    hgrepos = []
    issue_num = 5712
    keywords = []
    message_count = 18.0
    messages = ['85658', '91291', '91297', '98530', '107932', '107935', '107947', '107952', '120740', '197765', '205809', '205816', '205840', '210781', '222149', '222304', '222569', '222573']
    nosy_count = 11.0
    nosy_names = ['ggenellina', 'gpolo', 'nosklo', 'daku9999', 'dhalbert', 'luckycusp', 'pfhall', 'martinmiller', 'python-dev', 'serhiy.storchaka', 'som_veettil']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '19020'
    type = 'behavior'
    url = 'https://bugs.python.org/issue5712'
    versions = ['Python 2.7']

    @daku9999
    Copy link
    Mannequin Author

    daku9999 mannequin commented Apr 6, 2009

    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.

    @daku9999 daku9999 mannequin added topic-tkinter type-bug An unexpected behavior, bug, or error labels Apr 6, 2009
    @ggenellina
    Copy link
    Mannequin

    ggenellina mannequin commented Aug 5, 2009

    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 :( )

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Aug 5, 2009

    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.

    @nosklo
    Copy link
    Mannequin

    nosklo mannequin commented Jan 29, 2010

    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.

    @luckycusp
    Copy link
    Mannequin

    luckycusp mannequin commented Jun 16, 2010

    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.

    @luckycusp
    Copy link
    Mannequin

    luckycusp mannequin commented Jun 16, 2010

    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)

    @nosklo
    Copy link
    Mannequin

    nosklo mannequin commented Jun 16, 2010

    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

    @luckycusp
    Copy link
    Mannequin

    luckycusp mannequin commented Jun 16, 2010

    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

    @pfhall
    Copy link
    Mannequin

    pfhall mannequin commented Nov 8, 2010

    There seems some similarity between this issue and issue bpo-10316 which occurs on Linux.

    @serhiy-storchaka
    Copy link
    Member

    Is it still reproducible on 2.7?

    @martinmiller
    Copy link
    Mannequin

    martinmiller mannequin commented Dec 10, 2013

    Answering Serhiy Storchaka's question: Yes it's still reproducible with 2.7.6.

    @serhiy-storchaka
    Copy link
    Member

    What are values of Tkinter.wantobjects, Tkinter._support_default_root, Tkinter._default_root, Tkinter._default_root.wantobjects()? Before and after calling tkFileDialog.askopenfilenames().

    @martinmiller
    Copy link
    Mannequin

    martinmiller mannequin commented Dec 10, 2013

    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

    @serhiy-storchaka
    Copy link
    Member

    Thank you Martin.

    May be this issue was fixed in bpo-19020.

    @somveettil
    Copy link
    Mannequin

    somveettil mannequin commented Jul 3, 2014

    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.

    @serhiy-storchaka
    Copy link
    Member

    Som, what is full version of your Python?

    @somveettil
    Copy link
    Mannequin

    somveettil mannequin commented Jul 8, 2014

    @serhiy Storchaka - its Python 2.7.6

    @serhiy-storchaka
    Copy link
    Member

    This bug was fixed in 2.7.7.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant