String or Unicode type required, wxPython StaticText

妖精的绣舞 提交于 2019-12-11 07:10:34

问题


I'm trying to make a wxPython static text widget. For some reason I keep getting the error below.

Snippet:

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

Error:

", 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

回答1:


Label is a property of wx.Frame, and trying to assign anything other than a String to it is not allowed.
For reference: http://www.wxpython.org/docs/api/wx.Window-class.html#SetLabel (wx.Frame is a subclass of wx.Window)




回答2:


You need to specify all the argument names , self is being taken as datatype of some sort not as an argument, So in your code your have to replace self with parent = self



来源:https://stackoverflow.com/questions/5125377/string-or-unicode-type-required-wxpython-statictext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!