[pygtk] get_active() of CheckButton added to ScrolledWindow

Daniel Roesler diafygi at gmail.com
Wed Jan 21 14:35:42 WST 2009


Howdy all,

I'm just learning pygtk and glade, and I have a question about
accessing widgets that were added during an called function. In my
example, I have two buttons. The first button that adds a checkbox to
a scrolled window area. The second button prints the activity status
(True/False) of the checkbox.

The first button works fine. However, when I push button two, python
says "AttributeError: 'NoneType' object has no attribute
'get_active'". Obviously, this means that I'm not reaching the
checkbox widget correctly.

So my question, how can I get properties of a widget added after the
initial glade file was loaded?

Here's my program, and I've attached my glade file. Thanks all!
-----------------------
import pygtk
import gtk
import gtk.glade

class app_gui:
  def __init__(self):
    self.window = gtk.glade.XML("check.glade")
    dic = { "on_button1_clicked" : self.button1_clicked,
            "on_button2_clicked" : self.button2_clicked,
            "on_window1_destroy" : (gtk.main_quit) }
    self.window.signal_autoconnect(dic)
    return

  def button1_clicked(self,widget):
    button = gtk.CheckButton("test")
    self.window.get_widget("scrolledwindow1").add_with_viewport(button)
    button.show()
    return

  def button2_clicked(self,widget):
    status = self.window.get_widget("test").get_active()
    print status
    return

app=app_gui()
gtk.main()
-----------------------

Avast!
Daniel Roesler
diafygi at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check.glade
Type: application/x-glade
Size: 2268 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20090120/be1a0755/attachment.bin 


More information about the pygtk mailing list