Question

I have a very simple PyGTK application that contains 1 widget - a ComboBox. For some reason the ComboBox is not visible when I run my python script. The main window is visible just not the ComboBox. Note I have successfully determined that the ComboBox exists and I have added it to the main window (added the widget to a box then added that to the main window).

How can I get my ComboBox to appear?

import pygtk
pygtk.require('2.0')
import gtk


class MainApp:

    def __init__(self):
        self.encryptFile = True
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        main_box   = gtk.VBox(True, 10)

        client_store     = gtk.ListStore(str)
        self.clientFiles = ("a","b","c")

        for f in self.clientFiles:
            client_store.append([f])

        combobox        = gtk.ComboBox(client_store)
        renderer_text   = gtk.CellRendererText()
        combobox.pack_start(renderer_text, True)
        combobox.add_attribute(renderer_text, "text", 0)
        combobox.set_size_request(200,25)

        main_box.pack_start(combobox)
        main_box.show()

        self.window.add(main_box)
        self.window.show()

    def main(self):
        gtk.main()

    def delete_event(self, widget, event, data=None):
        return False

    def destroy(self, widget, data=None):
        gtk.main_quit()

if __name__ == "__main__":
    app = MainApp()
    app.main()
Was it helpful?

Solution

You forgot to show() your combo box. (It's often easier to do show_all() on the window.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top