【发布时间】: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 切换到超链接也无法正常工作。
请帮帮我。
【问题讨论】: