Search code examples
python-2.7wxpythonwxwidgetswx.textctrl

Encountering error while using Enter key, space bar, and backspace in wxpython wx.TextCtrl


alphabet keys(a-z) numeric keys(0-9) are mapped to unicode values, in a text editor which uses the wx.TextCtrl.

The line in which error encounters is given below,

self.statusbar.SetStatusText(engine.roman2mal(self.word.decode('utf-8')),0)

The error message is as given below,

Traceback (most recent call last):
  File "F:\EZHUTHANI_WIN\ezhuthani\beditor.py", line 498, in PreviewConv
    self.statusbar.SetStatusText(engine.roman2mal(self.word.decode('utf-8')),0)
  File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

Is there a way to map these keys(Enter, Space Bar, Backspace)? the other keys are mapped as given below,

keymap = {}
keymap['a'] = u'\u0D05';
keymap['A'] = u'\u0D06';

Solution

  • self.statusbar.SetStatusText(engine.roman2mal(self.word.decode('utf-8')),0) 
    

    You have to remove .decode function then the code will look like

     self.statusbar.SetStatusText(engine.roman2mal(self.word),0)