Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to create a Gtk.Button(""), when clicked will open the system default Web Browser using the label as the URL?

What I could do is...

import os
button = Gtk.Button(label="")
label = button.get_text()
os.system("sensible-browser " + label)

The above code does what I need it to do. Is this the correct way about doing this? Or is there a GTK function I should be using instead?

(Disclaimer: I am usually more specific with my questions, I feel like this is really basic and may not even be possible and I have checked the docs. Thank you!)

share|improve this question
up vote 4 down vote accepted

Two solutions in one! :)

First, there is a special button widget just for this job: GtkLinkButton. You create a GtkLinkButton just like a normal button. Here is a simple example program written with Python and PyGObject. PyGTK should look pretty similar:

from gi.repository import Gtk
window = Gtk.Window()
button = Gtk.LinkButton("", label="")

As an alternative, you can directly call the function gtk_show_uri.

If you need more sophisticated application launching stuff, take a look at Gio.

share|improve this answer
Wow, I was editing my question and you had already posted. Thanks again I'll try gtk_show_uri first. I forgot to mention its a toolbarbutton, but I'll go look and see if a LinkButton exists for the toolbar. – Dillon Gilmore Jun 27 '12 at 8:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.