Python, GTK and WebKit – creating a web browser – Part 3

Hey guys! Welcome to Part 3 of my Python, GTK and WebKit – creating a web browser tutorial. Part 3 will show you how to add an “About” button to the browser. The about dialog will look like:


Add the following few lines to the beginning of the code:

import Tkinter
from ScrolledText import *
import tkFileDialog
import tkMessageBox

Then we add the About button and dialog and all that. Here is the finished code for Part 3:

#!/usr/bin/env python
import gtk, webkit, os, pickle
import Tkinter
from ScrolledText import *
import tkFileDialog
import tkMessageBox

class Basic():

def __init__(self):
self.window = gtk.Window()
self.window.connect(‘destroy’, lambda w: gtk.main_quit())
self.window.set_default_size(640, 480)

self.navigation = gtk.HBox()
self.refresh = gtk.ToolButton(gtk.STOCK_REFRESH)
self.address_bar = gtk.Entry()
self.gobutton = gtk.Button(“GO!”)
self.about = gtk.ToolButton(gtk.STOCK_DIALOG_INFO)

self.view = gtk.ScrolledWindow()
self.webview = webkit.WebView()‘’)
self.webview.connect(‘title-changed’, self.change_title)
self.webview.connect(‘load-committed’, self.change_url)

self.refresh.connect(‘clicked’, self.refresh_page)
self.address_bar.connect(‘activate’, self.load_page)
self.gobutton.connect(‘clicked’, self.load_page)
self.about.connect(‘clicked’, self.about_browser)
self.navigation.pack_start(self.refresh, False)
self.navigation.pack_start(self.gobutton, False)
self.navigation.pack_start(self.about, False)
self.container = gtk.VBox()
self.container.pack_start(self.navigation, False)


def load_page(self, widget):
add = self.address_bar.get_text()
if add.startswith(‘http://’) or add.startswith(‘https://’) or add.startswith(‘file:///’):
add = ‘http://’ + add

def about_browser(self, widget):
root = Tkinter.Tk(className=””)
SeaSurfAbout = ScrolledText(root, width=50, height=50)
label = tkMessageBox.showinfo(“”, “Basic Web Browser \n Version 1.0″)

def change_title(self, widget, frame, title):
self.window.set_title(title + ” – Basic Web Browser”)

def change_url(self, widget, frame):
uri = frame.get_uri()

def refresh_page(self, widget):
browser = Basic()

I wonder what is in store for part 4?

Epic Chas Gamer 😀


Go on, you know you want to! Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: