wxPython WebView example

前端 未结 2 602
有刺的猬
有刺的猬 2020-12-13 15:51

I am writing a small reporting app using wxPython (wxAUI). I want to render my data as HTML, to be displayed in a WebView \'widget\'. I am looking for a sample \'hello world

相关标签:
2条回答
  • 2020-12-13 16:03

    This is a simple example that works for me.

    Make sure you are running the latest version of wxpython. (wxpython 2.9)

    import wx 
    import wx.html2 
    
    class MyBrowser(wx.Dialog): 
      def __init__(self, *args, **kwds): 
        wx.Dialog.__init__(self, *args, **kwds) 
        sizer = wx.BoxSizer(wx.VERTICAL) 
        self.browser = wx.html2.WebView.New(self) 
        sizer.Add(self.browser, 1, wx.EXPAND, 10) 
        self.SetSizer(sizer) 
        self.SetSize((700, 700)) 
    
    if __name__ == '__main__': 
      app = wx.App() 
      dialog = MyBrowser(None, -1) 
      dialog.browser.LoadURL("http://www.google.com") 
      dialog.Show() 
      app.MainLoop() 
    
    0 讨论(0)
  • 2020-12-13 16:25

    I posted to this thread after reading the first two entries, and in my post I said something like:

    There is an answer here, but it doesn't answer the question. The question was: How do I display an HTML file in a string in a browser window? The only answer opens the browser window, but gets data from a url and doesn't use the string contents.

    But then I researched the answer further, I took the postings here and came up with the actual answer to the original question, which was: How do I display from a string?:

    If you copy the html string assignment into the code sample, but replace the line:

      dialog.browser.LoadURL("http://www.google.com") 
    

    with:

      dialog.browser.SetPage(html_string,"")
    

    Everything should work as desired (displaying html page from a string (instead of url))

    Share and Enjoy!

    0 讨论(0)
提交回复
热议问题