String or Unicode type required, wxPython StaticTe

2019-08-01 09:33发布

问题:

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