I am using PyGtk 2.0. In my program I created a Dialog box which includes a Combobox. The Dialog box has no OK or Cancel button. The Dialog must close when the item in the Combobox is selected (means in onchange
event). But I could not destroy the Dialog without a manual close operation.
My relevant code is:
def mostrar_combobox(self, titulo, texto_etiqueta, lista):
"""
MÃ © All to show a combobox on screen and get the option chosen
"""
#print texto_etiqueta
#dialogo = gtk.Dialog(titulo, None, 0, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
dialogo = gtk.Dialog(titulo, None, gtk.DIALOG_MODAL, None)
etiqueta = gtk.Label(texto_etiqueta)
etiqueta.show()
dialogo.vbox.pack_start(etiqueta)
combobox = gtk.combo_box_new_text()
for x in lista:
combobox.append_text(x)
combobox.connect('changed', self.changed_cb)
#combobox.set_active(0)
combobox.show()
dialogo.vbox.pack_start(combobox, False)
response = dialogo.run()
elemento_activo = combobox.get_active()
return elemento_activo
dialogo.hide()
def changed_cb(self, combobox):
index = combobox.get_active()
if index > -1:
print index
Please advise how it can close on after onchange
.
I got a sample code posted here: http://pastie.org/10748579
But I could not reproduce same in my main app.