How to Embed Web Browser in Python GTK application using pymozembed

Embedding web browser or a screen for parsing HTML is easy in PyGTK. You only need to import the pymozembed, and add a few lines of code in your pygtk library, and you are set to go.

Here’s a sample PyGTK application that embeds a web-browser as well as a “Back” button for demonstration purpose :

PyGTK + browser Screenshot
PyMozEmbed PyGTK+ Mypapit Demo

# demo by mypapit ( – Sept 2009
import pygtk
import gtk
import gtkmozembed

class PyMoz:

def delete_event(self,widget,data=None):
return False

def destroy(self,widget,data=None):

def button_clicked(self,widget,data):

def __init__(self):
#init mozembed
self.moz = gtkmozembed.MozEmbed()
#create a Vertical Box Container to whole the browser
#and the “Back Button”
box = gtk.VBox(False,0)

#create a basic GTK+ window
win = gtk.Window()

#create and connect “Back” button, to add functionality
self.button = gtk.Button(“Back”)

#include both back button and the browser in the vertical box
#and the GTK+ window

#load the URL

#set the window title
win.set_title(“browser demo”)

#show all the stuffs on screen

#connect the delete_event and destroy event to make sure
#the app quits when the window is closed

if __name__ == “__main__”:


Download demo source code :

Working hard publishing papers and learning PyGTK

For the last few weeks I’ve been working hard to finish up my research project, most of it concerning about on mobile phone application usability and context-aware applications. This leaves me with less ┬átime to devote for this blog and I started to realise that I might have a ‘burn-out’ issue at the same time.

I’m still using Ubuntu in my daily work if you are curious (Ubuntu Netbook Remix 9.04 for netbook) and Ubuntu Jaunty Jackalope for my Intel Core 2 Duo Desktop PC. Besides writing those research papers, I’ve use what left of my time to learn PyGTK to enable me to code RAD app for GNU/Linux desktop environment.

I found out the references around the internet regarding PyGTK is very helpful to aid me in understanding the GTK+ bindings in python, which is not much different from its C counterpart.

Now that I’ve some time to spare until Hari Raya, I’ll try to use that time wisely to fill up this blog with a couple more of fresh new posts. So, keep reading!