Reputation: 10092
I have a GUI that has a frame, and I'm trying to put the main content into a Panel, adding components to it using absolute positioning. This is working on Linux, however when I run it on Windows there is an assert firing stating that:
wx._core.PyAssertionError: C++ assertion "!GetChildren().Find((wxWindow*)child)" failed at ..\..\src\common\wincmn.cpp(945) in wxWindowBase::AddChild(): AddChild() called twice
This is triggered by the first component I add to the panel. So my question is how to fix this, and why this problem doesn't happen on Linux?
Thanks for any help.
""" 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)
Upvotes: 0
Views: 837
Reputation: 22753
You must never call AddChild()
yourself as explicitly mentioned in the documentation.
You also should be aware of the fact that using absolute positions is a pretty bad idea which flat out never works in practice, especially when using pixels (and not dialog units).
Upvotes: 2