python gtk webkit display local html data

python, webkit

Solution

Try:

view.load_html_string(html, '')

Ref: http://webkitgtk.org/reference/webkit2gtk/unstable/WebKitWebView.html#webkit-web-view-load-html

Or, you can store your HTML in a file:

# Option 1
view.open('file:///path/to/file/page.html')

# Option 2
uri = 'page.html'
uri = os.path.realpath(uri)
uri = urlparse.ParseResult('file', '', uri, '', '', '')
uri = urlparse.urlunparse(uri)
view.load_uri(uri)

Problem

is there any way to use the webkit engine in python, combined with GTK to display html data that is stored within a python file, for example ``` import webkit import gtk html = "<h1>This is HTML content</h1><p>I am displaying this in python</p" gobject.threads_init() win = gtk.Window() view = webkit.WebView() view.open(html) win.add(view) win.show_all() gtk.main() ``` This is a crude demonstration of what i want, but the output should show the HTML content rendered within webkit. Can i do this, and if not, can i store a local html file somewhere and render that through webkit? Thanks,

Original source