How can I define a class as a Panel and afterwards call that class in my frame?
What you tried is close, but you're not properly calling the super class __init__
. When subclassing wxPython classes, however, it's generally best to use the following pattern so that you don't have to worry about which specific arguments you are passing to it. (This wouldn't have solved your problem, which was outside of the code in question, but it maybe makes it clearer what's happening.)
class Panel(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
# ... code specific to your subclass goes here
This ensures that anything passed in is handed on to the super class method with no additions or removals. That means the signature for your subclass exactly matches the super class signature, which is also what someone else using your subclass would probably expect.
If, however, you are not actually doing anything in your own __init__()
method other than calling the super class __init__()
, you don't need to provide the method at all!
As for your original issue:
but it gives me this error: in __init__ windows.Panel_swiginit(self,windows.new_Panel(*args, **kwargs)) TypeError: in method 'new_Panel', expected argument 1 of type 'wxWindow *'
(Edited) You were actually instantiating a wx.Panel() inside the __init__
rather than calling the super class __init__
, as Javier (and Bryan Oakley, correcting me) pointed out. (Javier's change of the "parent" arg to "*args" confused me... sorry to confuse you.)