How to create a HTML-dialog window in Python with Internet Explorer control?

You can embed a Internet Explorer window within a Python GUI application by using the wxWidgets WebView component (via wxPython). Unlike e.g. Qt that includes a standardised browser component across all platforms, wxWidgets uses the native browser on the host platform by default. You can also force IE (ignoring the user’s default browser) by setting the backend manually.

In the documentation it shows WEBVIEW_BACKEND_IE, but the actual value is available via wx.html2.WebViewBackendIE. The following is a complete working example, adapted from here:

import wx 
import wx.html2

class MyBrowser(wx.Frame): 
    def __init__(self, *args, **kwds): 
        wx.Frame.__init__(self, *args, **kwds) 
        sizer = wx.BoxSizer(wx.VERTICAL) 
        self.browser = wx.html2.WebView.New(self, backend=wx.html2.WebViewBackendIE) 
        sizer.Add(self.browser, 1, wx.EXPAND, 10) 
        self.SetSize((700, 700))

if __name__ == '__main__': 
    app = wx.App() 
    dialog = MyBrowser(None, -1) 

Of course, this will only work on Windows. For more information on WebViews in wxWidgets see the documentation.

If you are already using (Py)Qt for your application, Qt also supports embedding of ActiveX objects in windows using the QAxWidget class. There is a web browser example in the Qt documentation. Below is a minimal PyQt4 example:

browser = QAxContainer.QAxWidget() 
browser.setControl("<ActiveX ID>") # e.g. "{8856F961-340A-11D0-A96B-00C04FD705A2}"
browser.dynamicCall('Navigate(const QString&)', QtCore.QString(""))

Get regular FAQs tips & tutorials direct to your Inbox.


Related posts