1
votes

I have a situation where in i need to load "html" source in wxPython Panel in MAC.

Similar code I am pasting below.

This works perfectly fine: (Loads on Wx.Frame)

class Try_Webkit(wx.Frame): def init(self, parent, id, title): wx.Frame.init(self, parent, id, title)

    sizer = wx.BoxSizer(wx.VERTICAL)
    content_box = wx.BoxSizer(wx.VERTICAL)

    webkit = wx.webkit.WebKitCtrl(self, -1)
    webkit.SetPageSource(source)
    self.Show(True)

This below code isn't working (with wx.Panel, Nothing will be loaded, looks blank page)

class Try_Webkit(wx.Frame): def init(self, parent, id, title): wx.Frame.init(self, parent, id, title)

    panel = wx.Panel(self)

    sizer = wx.BoxSizer(wx.VERTICAL)
    content_box = wx.BoxSizer(wx.VERTICAL)

    webkit = wx.webkit.WebKitCtrl(panel, -1)
    webkit.SetPageSource(source)
    self.Show(True)

WxPython Version: 2.8.11.0 MAC : El Capitan 10.11.3

How can I load html source into Panel?

1

1 Answers

1
votes

You are not doing anything to manage the size of the webkit control, so it is staying at its very small default size. If you use your sizer like in the following then you will see it work as I think you are expecting it.

import wx
import wx.webkit

source = """\
<html><body>
<h1>Hello world</h1>
</body></html>
"""

class Try_Webkit(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        webkit = wx.webkit.WebKitCtrl(panel, -1, size=(200,200))
        webkit.SetPageSource(source)
        sizer.Add(webkit, 1, wx.EXPAND)
        panel.SetSizer(sizer)


app = wx.App()
frm = Try_Webkit(None, -1, "Try Webkit")
frm.Show()
app.MainLoop()