J-Cake
J-Cake

Reputation: 1618

open wx.html "<a>" tag in default browser

A wx.html frame contains an <a> tag. Upon clicking it, an error stating it was unable to open the requested HTML document appears.

import wx.html as html

class window(wx.Frame):

    def __init__(self, defaultFile=None, *args, **kwargs):
        super(window, self).__init__(*args, **kwargs)

    def prepareMainBody(self, code):

        self.panel = wx.Panel(self, -1)

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        self.htmlwin = html.HtmlWindow(self.panel, -1, style=wx.NO_BORDER)
        self.htmlwin.SetBackgroundColour(wx.WHITE)
        self.htmlwin.SetStandardFonts()
        self.htmlwin.SetPage("<html>Open a file to begin.</html>")

        vbox.Add((-1, 10), 0)
        vbox.Add(self.htmlwin, 1, wx.EXPAND)

        self.panel.SetSizer(vbox)

I have found an answer that uses wx.html2 but when I try to switch to it, I get an error saying it doesn't know what HTMLWindow is.

I wish to listen for the click on the <a> tag and open the URL in the user's default browser.

any suggestions welcome. thanks.

Upvotes: 1

Views: 206

Answers (1)

Zoe Plaxco
Zoe Plaxco

Reputation: 60

wx.html2 has a WebViewer class with associated handlers which might be able to be adapted to your uses.

https://wxpython.org/Phoenix/docs/html/wx.html2.WebView.html#wx.html2.WebView

I believe they can then be rendered to window.

Alternatively I would recommend you look into wx.lib.iewin which has a IEHtmlWindow which should be comparable.

Upvotes: 1

Related Questions