调用 wxSizer.Insert() 隐藏项目

发布于 2024-11-01 03:45:00 字数 436 浏览 4 评论 0原文

我正在尝试使用以下代码在该 sizer 中的最后一个元素之前将面板插入到 wxBoxSizer 中:

sizer = event.EventObject.Parent.GetSizer()

# Add new panel from xrc        
res = xrc.XmlResource('add_panel.xrc')
panel = res.LoadPanel(self, 'panel')
sizer.Insert(len(sizer.Children) -1, panel)

sizer.Layout()

但是当我运行它时,新面板显示正确,但以前是表中最后一个元素的按钮无处可见。有几次我看到该按钮部分被遮挡,很明显它仍然在原来的位置,但隐藏在新面板后面。问题是,调用了 sizer.Layout() 后,为什么它仍然处于原来的位置,我没有做什么来阻止它的不当行为?

I'm trying to insert a panel into a wxBoxSizer before the last element in that sizer using the following code:

sizer = event.EventObject.Parent.GetSizer()

# Add new panel from xrc        
res = xrc.XmlResource('add_panel.xrc')
panel = res.LoadPanel(self, 'panel')
sizer.Insert(len(sizer.Children) -1, panel)

sizer.Layout()

But when I run it the new panel shows correctly but the button which was previously the last element in the table is nowhere to be seen. On a couple of occasions I've seen the button partially obscured, so clearly it's still where it was before but hidden behind the new panel. Question is, having called sizer.Layout() why is it still in its old position and what am I not doing that would stop it misbehaving?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2024-11-08 03:45:00

你的养育方式可能是错误的。某些对象的父对象与实际结构和/或 sizer 不对应。试试这个示例:

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel = wx.Panel(self)
        self.button = wx.Button(self.panel, label="New")
        self.button.Bind(wx.EVT_BUTTON, self.OnButton)
        self.buttons = []
        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.button)
        self.panel.SetSizerAndFit(self.sizer)
        self.Show()

    def OnButton(self, e):
        button = wx.Button(self.panel, label=str(len(self.buttons)))
        self.buttons.append(button)
        self.sizer.Insert(len(self.sizer.Children) - 1, button)
        self.sizer.Layout()

app = wx.App(False)
win = MainWindow(None)
app.MainLoop()

Your parenting is probably wrong. Some of the object's parents do not correspond to the actual structure and / or sizers. Try this sample:

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel = wx.Panel(self)
        self.button = wx.Button(self.panel, label="New")
        self.button.Bind(wx.EVT_BUTTON, self.OnButton)
        self.buttons = []
        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.button)
        self.panel.SetSizerAndFit(self.sizer)
        self.Show()

    def OnButton(self, e):
        button = wx.Button(self.panel, label=str(len(self.buttons)))
        self.buttons.append(button)
        self.sizer.Insert(len(self.sizer.Children) - 1, button)
        self.sizer.Layout()

app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文