如何将重新定义的 wx 小部件添加到已创建的 box sizer 中?
How to add redefined wx widgets into already created box sizers?
我必须从 HyperlinkCtrl() 小部件切换到 StaticText() 并且在某些情况下还要反转或为 wxPython 中的一个特定字段调用不同的函数。
但是布局和调整器已经用字段列表创建,其中之一是我们之前说过的 HyperlinkCtrl()。所有布局和调整器都保存在两个单独的函数中。
所以切换是通过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 切换到超链接也无法正常工作。
请帮我解决这个问题。
您应该从一开始就将两个小部件添加到 sizer,但隐藏其中一个。当你想切换的时候,隐藏另一个,显示之前隐藏的那个。
我必须从 HyperlinkCtrl() 小部件切换到 StaticText() 并且在某些情况下还要反转或为 wxPython 中的一个特定字段调用不同的函数。
但是布局和调整器已经用字段列表创建,其中之一是我们之前说过的 HyperlinkCtrl()。所有布局和调整器都保存在两个单独的函数中。
所以切换是通过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 切换到超链接也无法正常工作。
请帮我解决这个问题。
您应该从一开始就将两个小部件添加到 sizer,但隐藏其中一个。当你想切换的时候,隐藏另一个,显示之前隐藏的那个。