[pygtk] glade and radio buttons.

Lang Hurst lang at tharin.com
Sun Jun 6 09:39:35 WST 2010


I'm trying to create an incredibly simple application just to learn gui 
programming, but I can't see how to work with radio buttons.

A sample from my glade looks like:

<child>
                      <widget class="GtkRadioButton" id="radiobutton1">
                        <property name="label" translatable="yes">Ch 
1</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="draw_indicator">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton2">
                        <property name="label" translatable="yes">Ch 
2</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">radiobutton1</property>
                      </widget>


...and so on.  11 radiobuttons, all belonging to group "radiobutton1"


I've tried many different things in my python file, things like

radio = [r for r in cbc['radiobutton1'].get_group() if r.get_active()]

(Saw that somewhere in my search)

So, I have in my Class:


dic = { "on_button_quit_clicked" : self.button_quit_clicked,
            "on_window_destroy" : self.button_quit_clicked,
            "on_MainWindow_destroy" : gtk.main_quit,
            "on_button_print_clicked" : self.button_print_clicked,
            "on_button_edit_clicked" : self.button_edit_clicked }


And those all work fine so far.  ie:

def button_print_clicked(self, widget):
           print "Print clicked"

And when I click the "Print" button, it prints to the terminal.  As I 
said, very basic.

Can someone tell me, show me, a very basic way of connecting to my radio 
buttons.  If I could get the thing to just print "Radio button 3 is 
selected"  I'd be ecstatic at this point.

I did read through the tutorial, but my old mind isn't flexible enough 
to go from the hardcoded gtk examples to separate glade + python files.

-- 
There are no stupid questions, just stupid people.



More information about the pygtk mailing list