Trebia Project.
Trebia Project.

Reputation: 940

How to add text and a html link in a single control in wxpython 4.0?

I am trying to add text and a link in the same line. Looking to internet I have only found either statictext (that will allow the text) and wx.adv.HyperlinkCtrl which only adds a link. Ideally if I can link them both in a single sentence will be ideal.

How I can do that?

Upvotes: 1

Views: 1241

Answers (1)

Rolf of Saxony
Rolf of Saxony

Reputation: 22438

Can't you just bundle them together with a sizer? e.g.

#!/usr/bin/python
import wx
import wx.lib.agw.hyperlink as hl

class Example(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title)
        self.InitUI()

    def InitUI(self):
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)
        text_sizer = wx.BoxSizer(wx.HORIZONTAL)
        textS = wx.StaticText(panel, label='Plain')
        textS.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False, 'Arial'))
        lnk = hl.HyperLinkCtrl(panel, -1, "wxPython Main Page",
                                  URL="http://www.wxpython.org/")
        textE = wx.StaticText(panel, label='Text')
        textE.SetFont(wx.Font(12, wx.SWISS, wx.ITALIC, wx.NORMAL, False, 'Courier'))
        self.SetSize((500, 150))
        text_sizer.Add(textS, 0, wx.ALIGN_CENTRE|wx.ALL, 0 )
        text_sizer.Add(lnk, 0, wx.ALL, 0 )
        text_sizer.Add(textE, 0, wx.ALL, 0 )
        sizer.Add(text_sizer)
        lnk.EnableRollover(True)
        lnk.SetToolTip(wx.ToolTip("Hello World!"))
        lnk.UpdateLink()
        self.SetSizer(sizer)
        self.Centre()
        self.Show(True)

if __name__ == '__main__':
    ex = wx.App()
    Example(None, 'A Hyperlink')
    ex.MainLoop()

enter image description here

Upvotes: 4

Related Questions