5

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,

1 Answer 1

7

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)
Sign up to request clarification or add additional context in comments.

1 Comment

how would i include a relative path?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.