pygobject add item to container within signal callback
<p>I'm working on a simple GUI application using PyGObject and GTK+ 3.  In this case, I'm wanting to have a button which brings up a dialog box that when you click OK will add an item to a list.  I have that part working but the final part that doesn't work is adding the item to the list.  It appears that an item does get added but it's empty.  It's selectable, though, just very small.  I've tried adding other kinds of widgets like Gtk.Button to see if it was something weird with Gtk.Label.  When I add the Gtk.Label in the constructor it works just fine.</p>

<p>Also I know this isn't quite the way to do things and there are some oddities with how I'm doing stuff in my code but I'm still just learning how to use PyGObject/GTK+ 3.  I imagine this problem is just something stupid I'm overlooking.</p>

<p>MainWindow.py</p>

<pre><code>import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import PromptDialog

class MainWindow(Gtk.Window):
  def addURLResponse(self, dialog, response, listBox):
    if(response == Gtk.ResponseType.OK):
      print(dialog.get_text())
      label = Gtk.Label(dialog.get_text())
      print(label.get_text())

      listBox.add(label)


    if(response != Gtk.ResponseType.DELETE_EVENT):
      dialog.destroy()


  def addURL(self, button):
    URLDialog = PromptDialog.PromptDialog("Add URL", self)

    URLDialog.connect('response', self.addURLResponse, button.get_parent().get_parent().get_parent().get_children()[1])
    URLDialog.show_all()


  def __init__(self):
    Gtk.Window.__init__(self, title="MPV-VJ")

    self.playlistsBar = Gtk.FlowBox()
    self.newBtn = Gtk.Button.new_with_label('+')
    self.playlistsBar.add(self.newBtn)
    self.playlistsList = Gtk.ListBox()
    self.playlistsView = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
    self.playlistsView.pack_start(self.playlistsBar, False, False, 0)
    self.playlistsView.pack_start(self.playlistsList, True, True, 0)

    self.playlist1View = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
    self.playlist1Bar = Gtk.FlowBox()
    self.addUrl1Btn = Gtk.Button.new_with_label('+URL')
    self.addUrl1Btn.connect('clicked', self.addURL)
    self.playlist1Bar.add(self.addUrl1Btn)
    self.addFile1Btn = Gtk.Button.new_with_label('+file')
    self.playlist1Bar.add(self.addFile1Btn)
    self.addDir1Btn = Gtk.Button.new_with_label('+dir')
    self.playlist1Bar.add(self.addDir1Btn)
    self.playlist1List = Gtk.ListBox()
    self.playlist1View.pack_start(self.playlist1Bar, False, False, 0)
    self.playlist1View.pack_start(self.playlist1List, True, True, 0)    

    self.playlist2View = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
    self.playlist2Bar = Gtk.FlowBox()
    self.addUrl2Btn = Gtk.Button.new_with_label('+URL')
    self.playlist2Bar.add(self.addUrl2Btn)
    self.addFile2Btn = Gtk.Button.new_with_label('+file')
    self.playlist2Bar.add(self.addFile2Btn)
    self.addDir2Btn = Gtk.Button.new_with_label('+dir')
    self.playlist2Bar.add(self.addDir2Btn)
    self.playlist2List = Gtk.ListBox()
    self.playlist2View.pack_start(self.playlist2Bar, False, False, 0)
    self.playlist2View.pack_start(self.playlist2List, True, True, 0)    

    self.plViewsBox = Gtk.HPaned()
    self.plViewsBox.pack1(self.playlist1View, True, False)
    self.plViewsBox.pack2(self.playlist2View, True, False)

    self.viewBox = Gtk.HPaned()
    self.viewBox.pack1(self.playlistsView, True, False)
    self.viewBox.pack2(self.plViewsBox, True, False)
    self.viewBox.set_position(200)

    self.logView = Gtk.ListBox()

    self.contentBox = Gtk.VPaned()
    self.contentBox.pack1(self.viewBox, True, False)
    self.contentBox.pack2(self.logView, True, False)
    self.contentBox.set_position(400)

    self.toolBar = Gtk.FlowBox()
    self.newBtn = Gtk.Button.new_with_label('new')
    self.toolBar.add(self.newBtn)
    self.loadBtn = Gtk.Button.new_with_label('load')
    self.toolBar.add(self.loadBtn)
    self.saveBtn = Gtk.Button.new_with_label('save')
    self.toolBar.add(self.saveBtn)

    self.mainBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
    self.mainBox.pack_start(self.toolBar, False, False, 0)
    self.mainBox.pack_start(self.contentBox, True, True, 0)

    self.add(self.mainBox)

    self.resize(1000, 500)
</code></pre>

<p>PromptDialog.py</p>

<pre><code>import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class PromptDialog(Gtk.Dialog):
  def get_text(self):
    return(self.entry.get_buffer().get_text())

  def __init__(self, message, mainWindow):
    Gtk.Dialog.__init__(self, title="Prompt")

    self.set_modal(True)
    self.set_transient_for(mainWindow)

    self.label = Gtk.Label(message)
    self.entry = Gtk.Entry()
    self.get_content_area().pack_start(self.label, True, True, 0)
    self.get_content_area().pack_start(self.entry, True, True, 0)

    self.add_button("OK", Gtk.ResponseType.OK)
    self.add_button("Cancel", Gtk.ResponseType.CANCEL)
</code></pre>

<p>The widget added to the window needs to have its .show() method called before it'll appear.</p>

python gtk3 gobject