ComboBoxText in Glade / GTK+3 / Python

Post here if you need help with creating a Graphical User Interface in Python.

ComboBoxText in Glade / GTK+3 / Python

Postby UbuntuJon » Tue Apr 16, 2013 11:22 am

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: I created a Gtk.ListStore() http://python-gtk-3-tutorial.readthedocs.org/en/latest/treeview.html#Gtk.ListStore, then I created a Gtk.CellRendererText() http://python-gtk-3-tutorial.readthedocs.org/en/latest/cellrenderers.html#cellrenderertext, then I created a Gtk.ComboBox() http://python-gtk-3-tutorial.readthedocs.org/en/latest/combobox.html. This was all in-line with example 13.3 here http://python-gtk-3-tutorial.readthedocs.org/en/latest/combobox.html.

Nothing works. When I open the combobox window a 2nd time, it is just a blank window. Can anyone help please?
UbuntuJon
 
Posts: 2
Joined: Tue Apr 16, 2013 11:15 am

Re: ComboBoxText in Glade / GTK+3 / Python

Postby micseydel » Tue Apr 16, 2013 5:50 pm

Hello, and welcome to the forum! I'm not a GUI guy, so I can't help directly with your problem, but I recommend you read this to help you get better help from those who could.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1443
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: ComboBoxText in Glade / GTK+3 / Python

Postby Yoriz » Tue Apr 16, 2013 7:34 pm

I don't know that gui library but in wxpython if you close a window all of its child controls are destroyed.
If you wanted to use the same window and its controls again rather then closing the window you could hide the window and then show it again when it was required.
If you didn't want to reuse the same window you would have to create a new instance of the window.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1049
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: ComboBoxText in Glade / GTK+3 / Python

Postby UbuntuJon » Tue Apr 16, 2013 9:20 pm

Hi Yoriz

Thanks so much. I didn't think of that! I've removed the "close window" default button, and added a custom one, that just hides the window.

Jon
UbuntuJon
 
Posts: 2
Joined: Tue Apr 16, 2013 11:15 am


Return to GUI

Who is online

Users browsing this forum: No registered users and 2 guests