如何仅在某些情况下在 wxpython 中取消设置或禁用 hyperlinkctrl

How to unset or disable hyperlinkctrl in wxpython only on some conditions

我在我的 panel.Under 上创建了 hyperlinkctrl 在某些情况下它应该是 hyperlink 但在其他情况下它应该只是文本而不是 link.

如何操作?

self.Author = wx.HyperlinkCtrl(self, -1, "", "~")

if true:
   self.Author.SetLabel(str(self.aList['Author']))
   self.Author.SetURL("mailto:%s" % str(self.aList['Author']))
else:
   self.Author.SetLabel("N/A")
   self.Author.SetURL("N/A")

在其他情况下 "N/A" 仍然是 linking。

谁能告诉我如何在 wxPython 中取消设置 url?

只需在以下之间切换:

self.Author.Enable()

和:

self.Author.Disable()

编辑: 重新显示 self.Author 时不带超链接

的下划线
import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, (-1, -1), wx.Size(300, 200))
        self.panel1 = wx.Panel(self)
        self.Author = wx.HyperlinkCtrl(self.panel1, -1, "", "http://127.0.0.1/some_directory/",pos=(30,50))
        self.Button = wx.Button(self.panel1, -1, "Click Me", pos=(80,100))
        self.Button.Bind(wx.EVT_BUTTON, self.OnButton)
        self.Show()

    def OnButton(self,event):
        self.Author.Hide()
        if self.Author.IsEnabled():
            self.Author = wx.StaticText(self.panel1, -1, "http://127.0.0.1/some_directory/", pos=(30,50))
            self.Author.Disable()
        else:
            self.Author = wx.HyperlinkCtrl(self.panel1, -1, "", "http://127.0.0.1/some_directory/", pos=(30,50))
            self.Author.Enable()
        self.Author.Show()
        self.Update()

if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None, -1, 'Hyperlink')
    app.MainLoop()