打开wx.html“<a>&#34; tag in default browser

时间:2018-04-24 12:04:21

标签: python html browser wxpython

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.

1 个答案:

答案 0 :(得分:1)

wx.html2有一个带有关联处理程序的WebViewer类,可以根据您的需要进行调整。

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

我相信它们可以渲染到窗口。

或者我建议你研究wx.lib.iewin,它有一个IEHtmlWindow应该是可比较的。