1

ここに私のコードがあります

python 2.7 & wxpython 2.8

http://pastie.org/4248326

これら 3 つの textctrl、chat_c(textctrl) で

chat_c と text_c をチャットルームのようにしたい

入力はchat_c 出力はtext_c

それが私が使う理由です

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)

これはエラーメッセージです

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

それは何ですか?Unicode タイプが必要ですか???

おそらくtextctrlのスタイルを変更しますか?

どうすればこれを修正できますか?

4

1 に答える 1

1

e.GetKeyCode() は int を返します。int をテキスト コントロールに渡さないでください。テキスト コントロールは、文字列または Unicode 文字列のみを受け取ります。そのため、int を文字列にキャストするか、別のことを行う必要があります。キャストする方法は次のとおりです。

key = str( e.GetKeyCode() )
于 2012-07-13T13:24:24.710 に答える