Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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. –  espectalll123 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... –  espectalll123 Jun 20 '12 at 20:11
    
And it works! That's why I typed in the title (closed) –  espectalll123 Jun 20 '12 at 20:12
    
Now I need help with this: askubuntu.com/questions/153788/how-can-i-set-a-spin-button –  espectalll123 Jun 20 '12 at 20:12

Your Answer

 
discard

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.