I am making a small GUI with tkinter. On it I have a Text widget, that should be able to accept input text from the user. The problem is that when the input text is not-ASCII (e.g. ááááá) the program crashes with the error below.
Could anybody please help me to see how to solve it? Thank you.
Below I paste a simple code that can be used for testing, and the error that I get.
As you can see non-ASCII text can be inserted with the insert method, but as soon as it receives non-ASCII text from the user in the GUI, it crashes.
CODE-----
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- from Tkinter import *
- import tkMessageBox
- import sys
- class App(object):
- def __init__(self,parent):
- # Frame
- fSize = 10
- self.f = Frame(parent,width=fSize,height=fSize)
- self.f.pack(padx=15,pady=15)
- self.tTale = Text(self.f, height=15, width=30, bg="grey")
- self.tTale.pack()
- self.tTale.insert(END, u'blá')
- #exit button
- Button(text="quit", command=quit) .pack(side=BOTTOM)
- root = Tk()
- root.title('Test')
- root.call('encoding', 'system', 'utf-8')
- app = App(root)
- root.mainloop()
2014-02-03 23:20:03.513 Python[82405:1107] An uncaught exception was raised
2014-02-03 23:20:03.524 Python[82405:1107] -[__NSCFConstantString characterAtIndex:]: Range or index out of bounds
2014-02-03 23:20:03.525 Python[82405:1107] (
0 CoreFoundation 0x00007fff8f59741c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8e1b4e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8f5972cc +[NSException raise:format:] + 204
3 CoreFoundation 0x00007fff8f47ebcb -[__NSCFString characterAtIndex:] + 91
4 Tk 0x00000001083b9f5d TkpInitKeymapInfo + 825
5 Tk 0x00000001083bfecb Tk_MacOSXSetupTkNotifier + 861
6 Tcl 0x000000010829bccd Tcl_DoOneEvent + 311
7 _tkinter.so 0x00000001082194a3 init_tkinter + 4450
8 Python 0x0000000107f3414d PyEval_EvalFrameEx + 8080
9 Python 0x0000000107f32093 PyEval_EvalCodeEx + 1641
10 Python 0x0000000107f388c8 _PyEval_SliceIndex + 929
11 Python 0x0000000107f354d4 PyEval_EvalFrameEx + 13079
12 Python 0x0000000107f32093 PyEval_EvalCodeEx + 1641
13 Python 0x0000000107f31a24 PyEval_EvalCode + 54
14 Python 0x0000000107f50c2c PyParser_ASTFromFile + 306
15 Python 0x0000000107f50cd3 PyRun_FileExFlags + 137
16 Python 0x0000000107f50821 PyRun_SimpleFileExFlags + 718
17 Python 0x0000000107f61363 Py_Main + 2995
18 libdyld.dylib 0x00007fff8be895fd start + 1
)
2014-02-03 23:20:03.526 Python[82405:1107] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8f59741c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8e1b4e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8f5972cc +[NSException raise:format:] + 204
3 CoreFoundation 0x00007fff8f47ebcb -[__NSCFString characterAtIndex:] + 91
4 Tk 0x00000001083b9f5d TkpInitKeymapInfo + 825
5 Tk 0x00000001083bfecb Tk_MacOSXSetupTkNotifier + 861
6 Tcl 0x000000010829bccd Tcl_DoOneEvent + 311
7 _tkinter.so 0x00000001082194a3 init_tkinter + 4450
8 Python 0x0000000107f3414d PyEval_EvalFrameEx + 8080
9 Python 0x0000000107f32093 PyEval_EvalCodeEx + 1641
10 Python 0x0000000107f388c8 _PyEval_SliceIndex + 929
11 Python 0x0000000107f354d4 PyEval_EvalFrameEx + 13079
12 Python 0x0000000107f32093 PyEval_EvalCodeEx + 1641
13 Python 0x0000000107f31a24 PyEval_EvalCode + 54
14 Python 0x0000000107f50c2c PyParser_ASTFromFile + 306
15 Python 0x0000000107f50cd3 PyRun_FileExFlags + 137
16 Python 0x0000000107f50821 PyRun_SimpleFileExFlags + 718
17 Python 0x0000000107f61363 Py_Main + 2995
18 libdyld.dylib 0x00007fff8be895fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6