大家能帮我解释一下这段代码吗?小弟刚学Python
#Boa:FramePanel:wxPanel3
import wx
def create(parent):
return wxPanel3(parent)
[wxID_WXPANEL3, wxID_WXPANEL3BUTTON1, wxID_WXPANEL3STATICTEXT1,
] = [wx.NewId() for _init_ctrls in range(3)]
class wxPanel3(wx.Panel):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Panel.__init__(self, id=wxID_WXPANEL3, name='', parent=prnt,
pos=wx.Point(198, 19, size=wx.Size(200, 100), style=self.style)
self.SetClientSize(wx.Size(192, 73))
self.staticText1 = wx.StaticText(id=wxID_WXPANEL3STATICTEXT1,
label='wxPanel3', name='staticText1', parent=self, pos=wx.Point(8,
, size=wx.Size(46, 13), style=0)
self.button1 = wx.Button(id=wxID_WXPANEL3BUTTON1, label='button1',
name='button1', parent=self, pos=wx.Point(8, 32), size=wx.Size(75,
23), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_WXPANEL3BUTTON1)
def __init__(self, parent, id, pos, size, style, name):
# style is added as a 'frame attribute' because many styles cannot be
# changed after creation.
self.style = wx.TAB_TRAVERSAL
self.style = style
self._init_ctrls(parent)
# This code must be added manually to override the design-time values
# This is only needed for those FramePanels that are not directly
# contained (when it's parent sizes it)
self.SetPosition(pos)
self.SetSize(size)
def OnButton1Button(self, event):
self.staticText1.SetLabel('Click!')
我是一名工人,业余爱好想学习一下编程,这几天发现了Python,感觉很好,就很想学,可是没有指导,中文资料又很少,学习起来很费劲也很茫目。
上面的这段代码我始终不明白,
我用颜色标记了不明白的地方大家帮我讲一下吧
类wxPanel3中的_init_ctrls函数是自定义的还是重写Panel类库中的?
wxID_WXPANEL3 两个他们是同一变量?
Python代码执行的顺序不是自上而下吗?
那么[wxID_WXPANEL3, wxID_WXPANEL3BUTTON1, wxID_WXPANEL3STATICTEXT1,
] = [wx.NewId() for _init_ctrls in range(3)]
先执行,还是类wxPanel3中
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Panel.__init__(self, id=wxID_WXPANEL3, name='', parent=prnt,
pos=wx.Point(198, 19, size=wx.Size(200, 100), style=self.style)
self.SetClientSize(wx.Size(192, 73))
.......
的这个函数先执行?
如果[wxID_WXPANEL3, wxID_WXPANEL3BUTTON1, wxID_WXPANEL3STATICTEXT1,
] = [wx.NewId() for _init_ctrls in range(3)]
先执行,那么 [wx.NewId() for _init_ctrls in range(3)]中的 _init_ctrls 不是还未初始化吗?不是要引起错误的吗?
哪们大哥能帮我理顺吗,这一点真的是不明白啊。或者详细解释一下这段代码是怎么执行的也可以
小弟谢谢了大家 了。