[pygtk] My dialog is empty when opened for second time
Lionel Dricot
zeploum at gmail.com
Wed Feb 24 16:06:36 WST 2010
Your object exists only once in self.builder and you destroy it so you
cannot retrieve it.
Instead of destroy, you should use "hide()" and instead of getting your
object each time from the builder, you should use "show()".
Don't worry, that's a common error when starting with pygtk :-)
Lionel
PS: I would write it this way (untested) :
class Sample:
def __init__ (self):
self.builder = gtk.Builder()
self.builder.add_from_file("../data/sample.glade")
self.builder.connect_signals(self)
self.dialog = self.builder.get_object("dialog1")
self.label = self.builder.get_object("label2")
self.window = self.builder.get_object("mywindow")
self.window.set_modal(True)
self.window.show_all()
def addDialog(self, sender):
self.dialog.show()
print self.label.get_text()
print self.dialog.get_title()
result = self.dialog.run()
if result == 1 :
print "ok!"
else :
print "no"
dialog.hide()
On Wed, Feb 24, 2010 at 8:10 AM, goli <g382nilieh at gmail.com> wrote:
> I have a problem with sowing a dialog using glade and pygtk, here is my
> code:
>
> class Sample:
> def __init__ (self):
> self.builder = gtk.Builder()
> self.builder.add_from_file("../data/sample.glade")
> self.builder.connect_signals(self)
>
> self.window = self.builder.get_object("mywindow")
> self.window.set_modal(True)
> self.window.show_all()
>
> def addDialog(self, sender):
> dialog = self.builder.get_object("dialog1")
> label = self.builder.get_object("label2")
> print label.get_text()
> print dialog.get_title()
> result = dialog.run()
> if result == 1 :
> print "ok!"
> else :
> print "no, thanks :D"
> dialog.destroy()
>
>
> I have connected addDialog to the clicked event of a button on "mywindow".
>
> The first time I click it, I can see "dialog1" which has "label2"
> inside. the next time I click that button, "dialog1" is opened but with
> no widgets inside!
> but in trminal the "label2" text and "dialog1" title is printed
> correctly, means that they are constructed but not visible.
>
> I also connected "dialog1" delete-event to gtk_widget_hide in the glade
> file, but no changes happend.
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20100224/50d2a1ac/attachment.htm
More information about the pygtk
mailing list