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

So, I'm developing my 1st app with GTK3 and I don't know how to link my buttons with their respective defs. Can anyone post a tutorial, an example or some docs?

Using next things for developing my app:

  • Ubuntu 12.04 LTS totally updated
  • Python 2.7.3
  • Obviously, GTK+ 3
  • Glade 3.12.1

The app which I'm developing is Virtuam (candidate at the App Showdown!)

share|improve this question
Are you trying to link the button to the event callback? – Reuben Swartz Jun 19 '12 at 18:28
up vote 5 down vote accepted

Have a look at this example on how to connect events to callbacks in Gtk 3 and Python. In short, you use the connect() method to connect a signal name (which is emitted when an event such as a button click occurs) to a callback, which is the function that will handle your event.

def __init__(self):
    # Other initialization code

    # We create a button
    self.button = Gtk.Button(label="Click Here")
    # We connect the 'clicked' signal to the callback
    self.button.connect("clicked", self.on_button_clicked)

def on_button_clicked(self, widget):
    # This function will be called whenever the user presses the button
    print "Hello World"

You can also watch the Gtk3 Introduction Workshop video that is part of the Ubuntu App Showdown.

If you're using Glade, you will need to make to make sure that the on_<name-of-your-button>_clicked() callback is defined in the code as a method of your window.

If you're using Quickly, that's all you'll need to worry about.

Otherwise, you'll need to manually connect the signal to the callback. You've got two options:

  • Do it in the code with self.builder.get_object('name-of-your-button').connect() - assuming builder is the name of your Gtk.Builder() in which you've loaded your Glade UI.
  • Do it with Glade looking at the properties of your button, choosing the signals tab and then writing the name of your callback in the 'clicked' signal.
share|improve this answer
Gracias de nuevo, David... pero igualmente, estoy usando Glade para crear la interfaz, así que no funciona. – espectalll Jun 20 '12 at 12:51
No worries, it should equally work with Glade. I've added an additional note on how to do that with Glade. – David Planella Jun 20 '12 at 20:09
But I've done the links with a dictionary, instead of using that... – espectalll Jun 20 '12 at 20:11
And it works! That's why I typed in the title (closed) – espectalll Jun 20 '12 at 20:12
Now I need help with this: – espectalll Jun 20 '12 at 20:12

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.