- wxPython Tutorial
- wxPython - Home
- wxPython - Introduction
- wxPython - Environment
- wxPython - Hello World
- wxPython - GUI Builder Tools
- wxPython - Major Classes
- wxPython - Event Handling
- wxPython - Layout Management
- wxPython - Buttons
- wxPython - Dockable Windows
- Multiple Document Interface
- wxPython - Drawing API
- wxPython - Drag and Drop
- wxPython Resources
- wxPython - Quick Guide
- wxPython - Useful Resources
- wxPython - Discussion
wxPython - HTMLWindow Class
wxHTML library contains classes for parsing and displaying HTML content. Although this is not intended to be a full-featured browser, wx.HtmlWindow object is a generic HTML viewer.
HtmlWindow class constructor takes a familiar look −
(Parent, id, pos, size, style)
This class supports the following styles −
S.N. | Styles & Description |
---|---|
1 | wxHW_SCROLLBAR_NEVER Never display scrollbars, not even when the page is larger than the window |
2 | wxHW_SCROLLBAR_AUTO Display scrollbars only if the page size exceeds window's size |
3 | wxHW_NO_SELECTION Don't allow the user to select text |
Following event binders are available for this class −
S.N. | Events & Description |
---|---|
1 | EVT_HTML_CELL_CLICKED A wxHtmlCell was clicked |
2 | EVT_HTML_CELL_HOVER The mouse passed over a wxHtmlCell |
3 | EVT_HTML_LINK_CLICKED A wxHtmlCell which contains an hyperlink was clicked |
Following member functions of this class are frequently used −
S.N. | Functions & Description |
---|---|
1 | AppendToPage() Appends HTML fragment to currently displayed text and refreshes the window |
2 | HistoryBack() Goes back to the previously visited page |
3 | HistoryForward() Goes to the next page in history |
4 | LoadPage() Loads a HTML file |
5 | OnLinkClicked() Called when a hyperlink is clicked |
6 | SetPage() Sets text tagged with HTML tags as page contents |
The following code displays a simple HTML browser. On running the code, a TextEntry Dialog pops up asking a URL to be entered. LoadPage() method of wx.HtmlWindow class displays the contents in the window.
import wx import wx.html class MyHtmlFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, size = (600,400)) html = wx.html.HtmlWindow(self) if "gtk2" in wx.PlatformInfo: html.SetStandardFonts() dlg = wx.TextEntryDialog(self, 'Enter a URL', 'HTMLWindow') if dlg.ShowModal() == wx.ID_OK: html.LoadPage(dlg.GetValue()) app = wx.App() frm = MyHtmlFrame(None, "Simple HTML Browser") frm.Show() app.MainLoop()