Display HTML using wxPython

vegaseat 0 Tallied Votes 910 Views Share

This small snippet shows how to load and display HTML (Hyper Text Markup Language) with wxPython's HtmlWindow(). This could be particularly useful with instruction and help text. HTML allows you to include pictures, fancy fonts and links.

# Experiment with wxPython's HtmlWindow
# tested with Python24 and wxPython26    vegaseat   17may2006

import wx
import  wx.html

class MyHtmlPanel(wx.Panel):
    class MyHtmlPanel inherits wx.Panel and adds a button and HtmlWindow
    def __init__(self, parent, id):
        # default pos is (0, 0) and size is (-1, -1) which fills the frame
        wx.Panel.__init__(self, parent, id)
        self.html1 = wx.html.HtmlWindow(self, id, pos=(0,30), size=(602,310))
        self.btn1 = wx.Button(self, -1, "Load Html File", pos=(0,0))
        self.btn1.Bind(wx.EVT_BUTTON, self.OnLoadFile)
        self.btn2 = wx.Button(self, -1, "Clear Page", pos=(120,0))
        self.btn2.Bind(wx.EVT_BUTTON, self.OnClearPage)
    def OnLoadFile(self, event):
        dlg = wx.FileDialog(self, wildcard = '*.htm*', style=wx.OPEN)
        if dlg.ShowModal():
            path = dlg.GetPath()
    def OnClearPage(self, event):

app = wx.PySimpleApp()
# create a window/frame, no parent, -1 is default ID, title, size
frame = wx.Frame(None, -1, "HtmlWindow()", size=(610, 380))
# call the derived class, -1 is default ID
# show the frame
# start the event loop