Search code examples
pythonwxpythonwxwidgets

Python: exactly 2 arguments (1 given)?


This is my file:

import wx


class MyFrame1 ( wx.Frame ):

    def __init__( self, parent ):
        wx.Frame.__init__ ( self, None, id = wx.ID_ANY, title = u"FB Converter to Python", pos = wx.DefaultPosition, size = wx.Size( 450,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )

        bSizer1 = wx.BoxSizer( wx.VERTICAL )

        self.infoCtrl1 = wx.InfoBar( self )
        self.infoCtrl1.SetShowHideEffects( wx.SHOW_EFFECT_SLIDE_TO_RIGHT, wx.SHOW_EFFECT_SLIDE_TO_LEFT )
        self.infoCtrl1.SetEffectDuration( 500 )
        bSizer1.Add( self.infoCtrl1, 0, wx.EXPAND, 5 )

        gSizer1 = wx.GridSizer( 0, 3, 2, 2 )

        self.staticText1 = wx.StaticText( self, wx.ID_ANY, u"Prodject Folder", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.staticText1.Wrap( -1 )
        gSizer1.Add( self.staticText1, 0, wx.ALL, 5 )

        self.dirPicker2 = wx.DirPickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select a folder", wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE )
        gSizer1.Add( self.dirPicker2, 0, wx.ALL, 5 )


        gSizer1.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )

        self.staticText3 = wx.StaticText( self, wx.ID_ANY, u"Convention Input Folder", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.staticText3.Wrap( -1 )
        gSizer1.Add( self.staticText3, 0, wx.ALL, 5 )

        self.dirPicker3 = wx.DirPickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select a folder", wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE )
        gSizer1.Add( self.dirPicker3, 0, wx.ALL, 5 )


        gSizer1.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )

        self.staticText4 = wx.StaticText( self, wx.ID_ANY, u"Convention Output Folder", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.staticText4.Wrap( -1 )
        gSizer1.Add( self.staticText4, 0, wx.ALL, 5 )

        self.dirPicker4 = wx.DirPickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select a folder", wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE )
        gSizer1.Add( self.dirPicker4, 0, wx.ALL, 5 )


        gSizer1.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )

        self.staticText5 = wx.StaticText( self, wx.ID_ANY, u"File Name To Be Converted", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.staticText5.Wrap( -1 )
        gSizer1.Add( self.staticText5, 0, wx.ALL, 5 )

        self.filePicker1 = wx.FilePickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select a file", u"Python files (*.py)|*.py", wx.DefaultPosition, wx.DefaultSize, wx.FLP_DEFAULT_STYLE|wx.FLP_FILE_MUST_EXIST )
        gSizer1.Add( self.filePicker1, 0, wx.ALL, 5 )


        gSizer1.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )


        bSizer1.Add( gSizer1, 1, wx.EXPAND, 5 )

        bSizer3 = wx.BoxSizer( wx.VERTICAL )

        sdbSizer1 = wx.StdDialogButtonSizer()
        self.sdbSizer1Apply = wx.Button( self, wx.ID_APPLY )
        sdbSizer1.AddButton( self.sdbSizer1Apply )
        self.sdbSizer1Cancel = wx.Button( self, wx.ID_CANCEL )
        sdbSizer1.AddButton( self.sdbSizer1Cancel )
        sdbSizer1.Realize();

        bSizer3.Add( sdbSizer1, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )


        bSizer1.Add( bSizer3, 1, wx.EXPAND, 5 )


        self.SetSizer( bSizer1 )
        self.Layout()

        self.Centre( wx.BOTH )

    def __del__( self ):
           # ------------ Add widget program settings

           # ------------ Call Populates

           self.Show()

           # ------------ Event handlers    

if __name__ == "__main__":
       app = wx.App(False)
       frame = MyFrame1()
       app.MainLoop()

and when I run it I am getting this error:

Exception AttributeError: "MyFrame1 instance has no attribute 'Show'" in del of <main.MyFrame1 instance at 0x000000000315C788>> ignored

Traceback (most recent call last): File "C:\myProjects\Python2\output\fbconvertBK.py", line 96, in frame = MyFrame1() TypeError: init() takes exactly 2 arguments (1 given)

the error is here:

frame = MyFrame1()

and the class first line is:

class MyFrame1 ( wx.Frame ):

Could someone please let me know where I am going wrong?


Solution

  • Your MyFrame1() class takes a parent argument, but you didn't supply it. The __init__ method dictates the arguments:

    def __init__( self, parent ):
    

    but you did not pass it in:

    if __name__ == "__main__":
       app = wx.App(False)
       frame = MyFrame1()
    

    Perhaps you meant to pass in app as the parent?

    if __name__ == "__main__":
       app = wx.App(False)
       frame = MyFrame1(app)
    

    Alternatively, make the parent argument optional by giving it a default value:

    def __init__(self, parent=None):
    

    Your __init__ implementation is otherwise not using the argument, so you could even just omit it here:

    def __init__(self):