如何仅在某些条件下取消设置或禁用wxpython中的hyperlinkctrl

如何仅在某些条件下取消设置或禁用wxpython中的hyperlinkctrl,wxpython,Wxpython,我已经在面板上创建了hyperlinkctrl。在某些情况下,它应该是超链接,但在其他情况下,它应该是文本而不是链接 如何做到这一点 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:

我已经在面板上创建了hyperlinkctrl。在某些情况下,它应该是超链接,但在其他情况下,它应该是文本而不是链接

如何做到这一点

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")
在else情况下,如果
“N/A”
仍处于链接状态

有谁能告诉我如何在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() 

另外,我不希望超链接下划线。我们可以删除它吗?您可以将self.Author重新定义为
StaticText
。如果您使用的是sizer,我认为您必须从sizer中删除面板,使用self.Author将面板重新定义为
StaticText
,将面板重新添加到sizer中,然后执行
self.Update()
,尽管这似乎有点过头了,只是为了去掉必须使用self.Update()的下划线?你能给我举个例子吗?谢谢Rolf。但是你被告知要设置尺寸器。仍然需要设置这些尺寸器吗?我的尺寸器有一个单独的功能