Frage

here is my code

python 2.7 & wxpython 2.8

http://pastie.org/4248326

these 3 textctrl, at the chat_c(textctrl)

i want to make chat_c and text_c like a chatting room

input is chat_c output is text_c

that is why i use

def OnReturnDown(self,e):

    key = e.GetKeyCode()
    self.text_c.SetValue(key) #for check out but doesn't work
    if key == wx.WXK_RETURN:
        self.text_c.SetValue(self.chat_c.GetValue()) 

 #key bind
    self.chat_c.Bind(wx.EVT_KEY_DOWN, self.OnReturnDown)

this is error message

Traceback (most recent call last):
  File "C:\workspace\wx_python_test\main_chat_client.py", line 239, in OnReturnDown
    self.text_c.SetValue(key) #for check out but doesn't work
  File "C:\Python27\Lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 1754, in SetValue
    return _controls_.TextCtrl_SetValue(*args, **kwargs)
TypeError: String or Unicode type required

what is that? Unicode type required???

maybe change the style of textctrl?

how can fix this?

War es hilfreich?

Lösung

e.GetKeyCode() returns an int. You don't pass an int to a text control. A text control only takes a string or a unicode string. So you'll need to cast the int into a string or do something else. Here's how to cast it:

key = str( e.GetKeyCode() )
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top