wxPython WebView 示例 [英] wxPython WebView example

查看:50
本文介绍了wxPython WebView 示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 wxPython (wxAUI) 编写一个小型报告应用程序.我想将我的数据呈现为 HTML,以显示在 WebView 的小部件"中.我正在寻找一个示例hello world"片段,它将显示如何在 WebView 小部件中显示/呈现 HTML 字符串 - 但一直无法找到一个示例 - 并且 WebView 小部件似乎没有很好的文档记录.

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' snippet that will show how to display/render an HTML string in a WebView widget - but have been unable to find a single example - and the WebView widget does not seem to be well documented.

有人可以提供这样一个例子的链接,或者(更好),在这里发布一个简短的片段,展示如何使用 WebView 小部件呈现 HTML 字符串?

Could someone please provide a link to such an example or (better still), post a short snippet here that shows how to use the WebView widget to render an HTML string?

# sample html string to display in WebView widget
html_string = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
       <title>Hello World!</title>
       <script type="text/javascript" src="jquery.js"></script>
       <style type="text/css" src="main.css"></style>
    </head>
    <body>
        <span id="foo">The quick brown fox jumped over the lazy dog</span>
        <script type="text/javascript">
        $(document.ready(function(){
           $("span#foo").click(function(){ alert('I was clicked!'); });
         });
        </script>
    </body>
</html>
"""

推荐答案

这是一个对我有用的简单示例.

This is a simple example that works for me.

确保您运行的是 最新 版本的 wxpython.(wxpython 2.9)

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() 

这篇关于wxPython WebView 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆