我有一个具有框架的GUI,我正在尝试将主要内容放入Panel中,使用绝对定位向其添加组件。这适用于Linux,但是当我在Windows上运行时,有一个断言触发说明:
wx._core.PyAssertionError: C++ assertion "!GetChildren().Find((wxWindow*)child)" failed at ..\..\src\common\wincmn.cpp(945) in wxWindowBase::AddChild(): AddChild() called twice
这是由我添加到面板的第一个组件触发的。所以我的问题是如何解决这个问题,为什么在Linux上不会发生这个问题?
感谢您的帮助。
""" Defines the main GUI panel for the app. """ import wx class MainGuiPanel(wx.Panel): def __init__(self, parent, size): wx.Panel.__init__(self, parent, size=size) self.SetMinSize(size) self.Bind(wx.EVT_PAINT, self.on_paint) self.createGui() def createGui(self): """ Create controls on the main panel UI. We use fixed positioning over layout managers as it gives a cleaner looking result. """ x = 7 y = 8 self.AddChild(wx.StaticText(self, -1, "PV Power" , wx.Point(x, y))) self.pvPowerTF = wx.TextCtrl(self,-1, "0 kW", wx.Point(x + 105, y - 2), wx.Size(100, 20), style=wx.TE_READONLY) self.AddChild(self.pvPowerTF) y += 28 self.AddChild(wx.StaticText(self, -1, "Load Power" , wx.Point(x, y))) self.loadPowerTF = wx.TextCtrl(self,-1, "0 kW", wx.Point(x + 105, y - 2), wx.Size(100, 20), style=wx.TE_READONLY) self.AddChild(self.loadPowerTF) y += 28 self.AddChild(wx.StaticText(self, -1, "Generator Power" , wx.Point(x, y))) self.generatorPowerTF = wx.TextCtrl(self,-1, "0 kW", wx.Point(x + 105, y - 2), wx.Size(100, 20), style=wx.TE_READONLY) self.AddChild(self.generatorPowerTF) def on_paint(self, event): """ Paint the background with a slight gradient """ dc = wx.PaintDC(self) x = 0 y = 0 w, h = self.GetSize() dc.GradientFillLinear((x, y, w, h), 'white', 'light grey', nDirection = wx.SOUTH)
答案 0 :(得分:1)
您绝不能像the documentation中明确提到的那样自己致电AddChild()
。
你也应该意识到使用绝对位置是一个非常糟糕的想法,它在实践中永远不会起作用,特别是在使用像素时(而不是对话单元)。