需要字符串或Unicode类型,wxPython StaticText

1 投票
2 回答
4289 浏览
提问于 2025-04-16 12:34

我正在尝试创建一个wxPython的静态文本控件。但不知为什么,我总是遇到下面的错误。

代码片段:

self.Label = wx.StaticText(self, pos=(sw/2.0 - w/2.0, sh/2.0 - h/2.0), label='hello')

错误信息:

", line 238, in make_label
    self.Label = wx.StaticText(self, pos=(sw/2.0 - w/2.0, sh/2.0 - h/2.0), label='hello')
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line 8500, in SetLabel
    return _core_.Window_SetLabel(*args, **kwargs)
TypeError: String or Unicode type required

2 个回答

0

你需要把所有的参数名称都写出来,self在这里被当作某种数据类型,而不是作为一个参数。所以在你的代码中,你需要把 self 替换成 parent = self

1

Label是wx.Frame的一个属性,给它赋值时只能用字符串,其他类型的值是不允许的。
参考链接:http://www.wxpython.org/docs/api/wx.Window-class.html#SetLabel(wx.Frame是wx.Window的一个子类)

撰写回答