Frage

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';
War es hilfreich?

Lösung

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) 

Andere Tipps

I'm not entirely sure what you to achieve, but it sounds like you want to be using

wx.WXK_BACK
wx.WXK_ESCAPE
wx.WXK_RETURN
...

perhaps

keymap = {}
keymap[wx.WXK_ESCAPE] = u'<ESCAPE>'
...
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top