[pygtk] How I do to use GtkRadiobutton in this application?

Marcus Habermehl bmh1980de at yahoo.de
Wed Nov 7 05:05:44 WST 2007


airton arantes schrieb:
> Hello folks, I did an application as example, the link to glade file
> and python source file are these:
> 
> http://paste.ubuntu-nl.org/43577/      this is the teste.glade
> http://paste.ubuntu-nl.org/43578/      this is the test.py
> 
> 
> I wanted the following:
> -> When I press OK button, instead of print "button ok pressed" I want
> that it print on the console "RadioButon1 was marked" or "RadioButton2
> was marked".

That's easy.

Change your function button_ok_callback().

Current you have

def button_ok_callback(*args):
	print "Button ok pressed"


If you change this to

def button_ok_callback(*args):
	if gladefile.get_widget("radiobutton1").get_active():
		print "RadioButton1 was marked"
	elif gladefile.get_widget("radiobutton2").get_active():
		print "RadioButton2 war marked"

The script prints this:

% python test.py
RadioButton1 was marked
RadioButton2 war marked
RadioButton2 war marked

As you know you can get a widget with get_widget(). The get_active()
method of the gtk.CheckButton() (the base class of gtk.RadioButton())
returns True if the button is checked, or False if the button isn't checked.

Best regards
Marcus


More information about the pygtk mailing list