[Python-bugs-list] [ python-Bugs-507962 ] tk.splitlist does not support Unicode

noreply@sourceforge.net noreply@sourceforge.net
Sat, 26 Jan 2002 12:22:24 -0800


Bugs item #507962, was opened at 2002-01-24 06:06
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=507962&group_id=5470

Category: Tkinter
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Matthias Huening (huening)
Assigned to: Nobody/Anonymous (nobody)
Summary: tk.splitlist does not support Unicode

Initial Comment:
Exception in Tkinter when trying to 'get' the Unicode-
items in a Listbox.
Reason: tk.splitlist does not support Unicode.

A simple example.
This works, no problems at all:

----
from Tkinter import *

root = Tk()

class Demo:
    def __init__(self, root):
        self.f = Frame(root)
        self.f.pack()

        self.l = Listbox(self.f)
        self.l.pack()

        self.but = Button(self.f, text='Get them', 
command=self.hol)
        self.but.pack()
       
        self.label = Label(self.f, text = 'Hi')
        self.label.pack(pady=10)
        
    def hol(self):
        out = ''
        for x in self.l.get(0, 'end'):
            out = out + '%s ' % x
        prog.label.configure(text = out)

if __name__ == '__main__':
    txt = 'Mühsam ernährt sich das Eichhörnchen'
    txt_list = txt.split()

    prog = Demo(root)
    
    for x in txt_list:
        prog.l.insert(END, x)  
        
    root.mainloop()
--------

But... when I change my input to
    	txt = u'Mühsam ernährt sich das Eichhörnchen'
or to
    	txt = 'Mühsam ernährt sich das Eichhörnchen'
    	txt = unicode(txt, 'Latin-1')
the words show up in te Listbox, but I cannot 
retrieve them from the 
Listbox:

Exception in Tkinter callback
Traceback (most recent call last):
  File "c:\python21\lib\lib-tk\Tkinter.py", line 
1285, in __call__
    return apply(self.func, args)
  File "C:\ALLESM~1\TK-PMW~1.PY", line 21, in hol
    for x in self.l.get(0,3):
  File "c:\python21\lib\lib-tk\Tkinter.py", line 
2293, in get
    return self.tk.splitlist(self.tk.call(
UnicodeError: ASCII encoding error: ordinal not in 
range(128)



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

>Comment By: Martin v. Löwis (loewis)
Date: 2002-01-26 12:22

Message:
Logged In: YES 
user_id=21627

Thanks for the report. This is fixed in _tkinter.c 1.123.

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

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=507962&group_id=5470