这是我的档案:
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()
当我运行它时,我收到此错误:
Exception AttributeError:“MyFrame1实例没有属性'Show'” 在del的< main .MyFrame1实例中 0x000000000315C788>>忽略
Traceback(最近一次调用最后一次):文件 “C:\ myProjects \ Python2 \ output \ fbconvertBK.py”,第96行,in frame = MyFrame1()TypeError: init ()正好接受2个参数(给定1个)
错误在这里:
frame = MyFrame1()
并且第一行是:
class MyFrame1 ( wx.Frame ):
有人可以让我知道我哪里出错吗?
答案 0 :(得分:3)
您的MyFrame1()
课程采用 parent
参数,但您没有提供。 __init__
方法指示参数:
def __init__( self, parent ):
但你没有传递它:
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame1()
也许您打算将app
作为父母传递?
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame1(app)
或者,通过为其提供默认值来使父参数可选:
def __init__(self, parent=None):
你的__init__
实现不会使用参数,所以你甚至可以在这里省略它:
def __init__(self):
答案 1 :(得分:0)
你的MyFrame1
课程需要一个论点:
class MyFrame1 ( wx.Frame ):
def __init__( self, parent ):
pass
因此,您必须使用frame = MyFrame1(parent)
进行实例化,而不是frame = MyFrame1()
如果MyFrame1
并不总是需要父框架,您可以使用可选参数。
class MyFrame1 ( wx.Frame ):
def __init__( self, parent=None ):
pass
正如python-ninja Martijn Pieters所指出的那样,你当然只需删除它,因为__init__
实现并不依赖于parent
参数。
def __init__(self):