Search code examples
comboboxpygtk

PyGTK ComboBox: how to populate when down-arrow is clicked


(PyGTK 2.24.2 with 32-bit Python 2.7.11.)

How do I populate a ComboBox dynamically when the down-arrow is clicked? I want the box to list the Windows COM ports (retrieved via win32file.QueryDosDevice) that exist at the moment it is clicked.


Solution

  • Create a callback function related to the "popdown" gtk.ComboBox Signal where you remove all texts in the connected liststore and add the new ones.

    Definition (in your screen design, right after creating the combo):

    self.combobox.connect ( 'popdown', self.callback )
    

    Callback (best located in a separate part of the code):

    def callback(self, combobox, user_param1, ...)
    

    See http://www.pygtk.org/pygtk2reference/class-gtkcombobox.html#signal-gtkcombobox--popdown