python - How to pass UTF-8 string from wx.TextCtrl to wx.ListCtrl -


if enter baltic characters in textctrl , click button test1 have error

"inicodeencodeerror: 'ascii' codec can't encode characters in position 0-3:                       ordinal not in range(128)" 

button test2 works fine.

#!/usr/bin/python # -*- coding: utf-8 -*-  import wx  class myframe(wx.frame):     def __init__(self, parent, id, title):         wx.frame.__init__(self, parent, id, title, (-1, -1), wx.size(450, 300))          self.panel = wx.panel(self)          self.input_area = wx.textctrl(self.panel, -1, '',(5,5),(200,200), style=wx.te_multiline)         self.output_list = wx.listctrl(self.panel, -1, (210,5), (200,200), style=wx.lc_report)         self.output_list.insertcolumn(0, 'column')         self.output_list.setcolumnwidth(0, 100)           self.btn1 = wx.button(self.panel, -1, 'test1', (5,220))         self.btn1.bind(wx.evt_button, self.ontest1)          self.btn2 = wx.button(self.panel, -1, 'test2', (100,220))         self.btn2.bind(wx.evt_button, self.ontest2)          self.centre()      def ontest1(self, event):         self.output_list.insertstringitem(0,str(self.input_area.getvalue()).decode('utf-8'))      def ontest2(self, event):         self.output_list.insertstringitem(0,"ąčęėįš".decode('utf-8'))  class myapp(wx.app):      def oninit(self):          frame = myframe(none, -1, 'encoding')          frame.show(true)          return true  app = myapp(0) app.mainloop() 

update 1

i have tried code on 2 windows 7 ultimate x64 computers.

both have python 2.7 , wxpython2.8 win64 unicode python 2.7

in both machines have same error.

replace def ontest1(self, event): self.output_list.insertstringitem(0,str(self.input_area.getvalue()).decode('utf-8'))

with

def ontest1(self, event):

    self.output_list.insertstringitem(0,self.input_area.getvalue()) 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -