Why does not my wx.html.HtmlWindow work?

Rob Williscroft rtw at freenet.co.uk
Sun Apr 8 13:01:29 EDT 2007


liqfemail at gmail.com wrote in
news:1176003505.794328.62170 at n76g2000hsh.googlegroups.com in
comp.lang.python: 

> Below are my source code:
> 
> 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()
>         html.LoadPage("
>         http://www.pythonthreads.com/articles/python/incorporating-into
>         -wxpython-part-1.html") 
> 
> app = wx.PySimpleApp()
> frm = MyHtmlFrame(None, "Simple HTML Browser")
> frm.Show()
> app.MainLoop()
> 
> It is just an example in the book "wxPython in action". But every time
> when I try to get it run, my CPU is fully occupied, and there is no
> frame that comes into existence. Why?
> 

I think your problem is that you call LoadPage before app.MainLoop() is
called, IOW you need to call LoadPage in an event handler:

import wx
import wx.html

class MyHtmlFrame(wx.Frame):
  
    HOME = "http://www.google.co.uk"
    
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(600,400))
        self.html = wx.html.HtmlWindow (self)
        if "gtk2" in wx.PlatformInfo:
            self.html.SetStandardFonts()
        self.done_show = False
        wx.EVT_IDLE( self, self.OnShow )
        self.html.SetPage( 
            "<a href='%s'>Loading ...</a>" % self.HOME
          )
      
    def OnShow( self, event ): 
        if self.done_show:
          return
        self.done_show = True
        self.html.LoadPage( self.HOME ) 

app = wx.PySimpleApp()
frm = MyHtmlFrame(None, "Simple HTML Browser")
frm.Show()
app.MainLoop()

Note: the URL you loading takes ages to show, which is why I
use: http://www.google.co.uk above.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list