Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need a simple "Hello World" example using the Webkit library in Python

Tags:

python

webkit

Does anyone know of a simple "Hello World" example for using the Webkit library in Python? I have a GTK window, and inside I want to put Webkit.

With Python/mozembed (Mozilla/Gecko), this is simple:

mozembed = gtkmozembed.MozEmbed()
mozembed.load_url('http://google.com/')

..and I have already created my browser, how do I do this with WebKit?

like image 426
Miuler Avatar asked Mar 15 '09 01:03

Miuler


2 Answers

Did you check the Python bindings for the WebKit GTK+ port. In one of the directory there are demos on how to use it, including a browser: python demos/tabbed_browser.py

You could check also the slides of a FOSDEM by Alp Toker on WebKit GTK+ (pdf) Developing hybrid Web/GTK+ rich internet applications.

import gtk 
import webkit 

view = webkit.WebView() 

sw = gtk.ScrolledWindow() 
sw.add(view) 

win = gtk.Window(gtk.WINDOW_TOPLEVEL) 
win.add(sw) 
win.show_all() 

view.open("http://w3.org/") 
gtk.main()

That should give you good hints for starting.

like image 65
karlcow Avatar answered Nov 05 '22 17:11

karlcow


Now with WebKitGtk2

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')

from gi.repository import Gtk, WebKit2

window = Gtk.Window()
window.set_default_size(800, 600)
window.connect("destroy", Gtk.main_quit)

scrolled_window = Gtk.ScrolledWindow()
webview = WebKit2.WebView()
webview.load_uri("https://google.cl")
scrolled_window.add(webview)

window.add(scrolled_window)
window.show_all()
Gtk.main()
like image 32
Fabio Duran Verdugo Avatar answered Nov 05 '22 15:11

Fabio Duran Verdugo