Ubuntu: ComboBoxText in Glade / GTK+3 / Python - disappears when displayed 2nd time



Question:

I'm trying to implement a drop down list in an Ubuntu app using Glade (GTK+3) and Python. I can get the ComboBoxText to display, populated with strings. However when I close the window it is contained in and then re-open it, the combobox is not there, just a completely blank window.

I added the ComboBoxText widget in question to a window in Glade. I then added this code in my Python programme:

def on_button_edit_clicked(self, widget):      """ display list of events already stored, and allow deletion """           self.combo = self.builder.get_object('combo_box')      self.store = Gtk.ListStore(str)        self.store.append(['hello'])      self.store.append(['goodbye'])      self.combo.set_model(self.store)       event_editor = self.builder.get_object("event_editor")     event_editor.show()   

I even tried destroying the widget to see if that helps:

def on_event_editor_destroy(self, widget):      self.combo.destroy()      self.store = Gtk.ListStore(str)      self.combo.set_model(self.store)  

EDIT:

I have since tried some alternative code, that included a CellRendererText object, but still no luck.

These are my sources (unfortunately I can't link to them all as I don't have enough of a reputation):

I created a Gtk.ListStore(), then I created a Gtk.CellRendererText(), then I created a Gtk.ComboBox(). This was all in-line with example 13.3 here.

Nothing works. When I open the combobox window a 2nd time, it is just a blank window. Can anyone help please?


Solution:1

The problem lies with the Window.

You should implement a callback for the 'delete-event' signal of the Window widget.

def on_event_editor_delete_event(self, widget, event):      self.event_editor.hide()      return True  

This callback hides the Window and returns True so the event isn't propagated further (i.e. the Window isn't destroyed, including your ComboBox).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »