【问题标题】:How to add redefined wx widgets into already created box sizers?如何将重新定义的 wx 小部件添加到已创建的 box sizer 中?
【发布时间】:2016-04-04 07:09:03
【问题描述】:

我必须从 HyperlinkCtrl() 小部件切换到 StaticText() 并在某些条件下反转或为 wxPython 中的一个特定字段调用不同的函数。

但是 layout 和 sizer 已经创建了字段列表,其中之一是我们之前所说的 HyperlinkCtrl()。所有 layouts 和 sizer 都保存在两个单独的函数中。

所以切换是通过HyperlinkCtrl()的Disabled()Enabled()函数实现的。

问题是在使用 StaticText() 重新定义后,无法将其添加到 box sizer 中。

def createLayout(self):

         #some code 
         ........
         self.Author = wx.HyperlinkCtrl(self, -1, "", "~")
         self.Author.SetFont(self.fontSmall)
         ..........

def createSizers(self):
        ............
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        ...............
        self.DetailsSizer = wx.BoxSizer(wx.VERTICAL)
        self.DetailsSizer.Add(self.Author, 0, wx.ALIGN_LEFT)
        .................
def changeFunc(self):
        if true
          self.hyperFunc()
        else
          self.statisFunc()

为了禁用和启用小部件,我执行了以下方法。

def staticFunc(self):
    # Author & URL

    self.Author.Hide()
    if self.Author.IsEnabled():
        self.Author = wx.StaticText(self, -1, "N/A")
        self.Author.SetFont(self.fontSmall)
        self.Author.Disable()
    self.Author.Show()

def hyperFunc(self):
     self.Author = wx.HyperlinkCtrl(self, -1, "", "")
     self.Author.Enable()
     self.Author.SetURL("name")

通过上述更改创建了 staticText,但我无法放入 sizer,并且从 staticText 切换到超链接也无法正常工作。

请帮帮我。

【问题讨论】:

    标签: wxpython wxwidgets


    【解决方案1】:

    您应该从一开始就将两个小部件都添加到 sizer 中,但隐藏其中一个。当你想切换时,隐藏另一个并显示之前隐藏的那个。

    【讨论】:

    • 感谢您的回复,您能给我一些例子吗?
    猜你喜欢
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    相关资源
    最近更新 更多