When using wxpython, I frequently get TypeErrors about something that is - as far as I can see - already fulfilled.
Examples:
Another one:
Am I missing something about 'Types' in python, something about the 'item' in question, or may the Error Message just be misleading?
Examples:
# -*- coding: cp1252 -*- import wx, wx.grid, wx.lib.scrolledpanel class tiropanel(wx.lib.scrolledpanel.ScrolledPanel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) #self.tirogrid = tirogrid(self, id) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add((50, 50)) #hbox.Add(self.tirogrid, 0, wx.EXPAND) self.SetSizerAndFit(hbox) self.SetupScrolling(self) ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ###### # Mainframe-Fenster aufbauen # ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ###### class Mainframe(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size = (1200, 900)) self.tiropanel = tiropanel(self, id) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.tiropanel, 0, wx.EXPAND) self.SetSizer(vbox) self.Show() ######################################################################### # # # # # # # # # # # # # ######################################################################### ########### Hauptprogramm ########## ######################################################################### # # # # # # # # # # # # # ######################################################################### if __name__ == "__main__": app = wx.App(0) Mainframe(None, -1, "Mainframe") app.MainLoop()gives
Error:Traceback (most recent call last):
File "TypeErrorExpl02.py", line 51, in <module>
Mainframe(None, -1, "Mainframe")
File "TypeErrorExpl02.py", line 29, in __init__
self.tiropanel = tiropanel(self, id)
File "TypeErrorExpl02.py", line 17, in __init__
self.SetupScrolling(self)
File "pythonxy\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\scrolledpanel.py", line 71, in SetupScrolling
self.SetScrollRate(rate_x, rate_y)
File "pythonxy\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 179, in SetScrollRate
return _windows_.ScrolledWindow_SetScrollRate(*args, **kwargs)
TypeError: in method 'ScrolledWindow_SetScrollRate', expected argument 1 of type 'wxScrolledWindow *'
SetupScrolling gets 'self', that is tiropanel(wx.lib.scrolledpanel.ScrolledPanel), and as ScrolledPanel, it should be of the Type wxScrolledWindow. Another one:
# -*- coding: cp1252 -*- import wx, wx.grid, wx.lib.scrolledpanel class Linkespanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) self.Eckpanel = Eckpanel(self, id) self.tiropanel = tiropanel(self, id) hbox = wx.BoxSizer(wx.HORIZONTAL) #hbox.Add(Eckpanel, 0, wx.EXPAND) hbox.Add((200, 50)) hbox.Add(tiropanel, 0, wx.EXPAND) self.SetSizerAndFit(hbox) class tiropanel(wx.lib.scrolledpanel.ScrolledPanel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) #self.tirogrid = tirogrid(self, id) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add((50, 50)) #hbox.Add(self.tirogrid, 0, wx.EXPAND) self.SetSizerAndFit(hbox) #self.SetupScrolling(self) class Eckpanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) #ticosize = ticolgrid.GeSize() hbox = wx.BoxSizer(wx.HORIZONTAL) self.SetSizerAndFit(hbox) self.SetMinSize((200, 50)) ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ###### # Mainframe-Fenster aufbauen # ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ###### class Mainframe(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size = (1200, 900)) self.Linkespanel = Linkespanel(self, id) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.Linkespanel, 0, wx.EXPAND) self.SetSizer(vbox) self.Show() ######################################################################### # # # # # # # # # # # # # ######################################################################### ########### Hauptprogramm ########## ######################################################################### # # # # # # # # # # # # # ######################################################################### if __name__ == "__main__": app = wx.App(0) Mainframe(None, -1, "gives
Error:Traceback (most recent call last):
File "TypeErrorExpl01.py", line 77, in <module>
Mainframe(None, -1, "Mainframe")
File "TypeErrorExpl01.py", line 55, in __init__
self.Linkespanel = Linkespanel(self, id)
File "TypeErrorExpl01.py", line 15, in __init__
hbox.Add(tiropanel, 0, wx.EXPAND)
File "pythonxy\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 12697, in Add
return _core_.Sizer_Add(*args, **kwargs)
TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item
Even a ScrolledPanel should be in some way a wx.Window, so the requirement of being that is already fulfilled... as far as I can see. Am I missing something about 'Types' in python, something about the 'item' in question, or may the Error Message just be misleading?