这是我在Boa Constructor中的第一个应用程序,也是我第一次使用wxPython。
#Boa:Frame:Frame1
import wx
choiceList = ['DAR', 'Impex', 'Endon', 'Astro', 'Ansell', 'Other']
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1BUTTONSELECTDIR, wxID_FRAME1BUTTONSELECTFILE,
wxID_FRAME1CHOICESUPPLIER,
] = [wx.NewId() for _init_ctrls in range(4)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(517, 20), size=wx.Size(400, 492),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(392, 458))
self.choiceSupplier = wx.Choice(choices=choiceList, id=wxID_FRAME1CHOICESUPPLIER,
name=u'choiceSupplier', parent=self, pos=wx.Point(48, 176),
size=wx.Size(120, 21), style=0)
self.choiceSupplier.Bind(wx.EVT_CHOICE, self.OnChoiceSupplierChoice,
id=wxID_FRAME1CHOICESUPPLIER)
def __init__(self, parent):
self._init_ctrls(parent)
def OnChoiceSupplierChoice(self, event):
supplier = choiceList[self.choiceSupplier.GetSelection()]
print supplier
单击运行应用程序时,我的代码运行正常。但是,当我尝试在设计器中编辑它时,我收到一个错误:
16:17:06: Traceback (most recent call last):
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\Models\wxPythonControllers.py", line 78, in OnDesigner self.showDesigner()
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\Models\wxPythonControllers.py", line 143, in showDesigner designer.refreshCtrl()
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\Views\Designer.py", line 399, in refreshCtrl self.initObjectsAndCompanions(objCol.creators[1:], objCol, deps, depLnks)
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\Views\InspectableViews.py", line 127, in initObjectsAndCompanions self.initObjCreator(constr)
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\Views\Designer.py", line 529, in initObjCreator InspectableObjectView.initObjCreator(self, constrPrs)
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\Views\InspectableViews.py", line 155, in initObjCreator constrPrs.comp_name, constrPrs.params)
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\Views\Designer.py", line 483, in loadControl compClass=CtrlCompanion, evalDct=self.model.specialAttrs)
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\Views\Designer.py", line 62, in setupArgs args = InspectableObjectView.setupArgs(self, ctrlName, params, dontEval, evalDct=evalDct)
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\View \InspectableViews.py", line 63, in setupArgs evalDct)
16:17:06: File "C:\Python27\Lib\site-packages\boa-constructor\PaletteMapping.py", line 158, in evalCtrl return eval(expr, globals(), localsDct)
16:17:06: File "<string>", line 1, in <module>
16:17:06: NameError: name 'choiceList' is not defined
答案 0 :(得分:1)
在寻找其他与boa-constructor相关的东西的时候偶然发现了这个问题,对不起,如果在这里回答有点死的帖子被视为失礼,我是新来的。
无论如何,我最好的猜测是你自己搞砸了_init_ctrls,即使是“不要编辑”评论。我自己试过几次,好的蟒蛇不能很好地处理。更改后
self.choiceSupplier = wx.Choice(choices=choiceList
到
self.choiceSupplier = wx.Choice(choices=''
你可以再次进入设计师,并且能够拥有和填充wx.Choice项目我在 init 中移动了列表:
#Boa:Frame:Frame1
import wx
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1CHOICESUPPLIER,
] = [wx.NewId() for _init_ctrls in range(2)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(517, 20), size=wx.Size(408, 496),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(392, 458))
self.choiceSupplier = wx.Choice(choices=self.choiceList,
id=wxID_FRAME1CHOICESUPPLIER, name=u'choiceSupplier', parent=self,
pos=wx.Point(0, 0), size=wx.Size(392, 21), style=0)
self.choiceSupplier.Bind(wx.EVT_CHOICE, self.OnChoiceSupplierChoice,
id=wxID_FRAME1CHOICESUPPLIER)
def __init__(self, parent):
self.choiceList = ['DAR', 'Impex', 'Endon', 'Astro', 'Ansell', 'Other']
self._init_ctrls(parent)
def OnChoiceSupplierChoice(self, event):
supplier = choiceList[self.choiceSupplier.GetSelection()]
print supplier
if __name__ == '__main__':
application = wx.PySimpleApp()
someFrame = Frame1(None)
someFrame.Show()
application.MainLoop()
问题可能是设计师会话如何分析文件,错过了班级外部的列表。