2016-08-27 6 views
1

2列のGtkComboBoxを作成しようとしています。私はいくつかの例を取り上げ、私は適応しようとしているが、成功していない。 2番目の列になる項目のみが表示されます。2列のコンボボックス

#!/usr/bin/env python3 

import gi 
gi.require_version('Gtk', '3.0') 
from gi.repository import Gtk 

class ComboBox(Gtk.Window): 
    def __init__(self): 
     Gtk.Window.__init__(self) 
     self.set_title("ComboBox") 
     self.set_default_size(150, -1) 
     self.connect("destroy", Gtk.main_quit) 

     slist = Gtk.ListStore(str, str) 
     slist.append(['01', 'Ferro']) 
     slist.append(['07', 'Uranio']) 
     slist.append(['08', 'Cobalto']) 

     combobox = Gtk.ComboBox() 
     combobox.set_model(slist) 
     combobox.set_active(0) 
     combobox.set_wrap_width(2) 
     self.add(combobox) 

     cellrenderertext = Gtk.CellRendererText() 
     combobox.pack_start(cellrenderertext, True) 
     combobox.add_attribute(cellrenderertext, "text", 1) 

window = ComboBox() 
window.show_all() 

Gtk.main() 

私はこのようなGtkComboBoxを作成します:

enter image description here

答えて

1

表示される各列のCellRendererTextがなければなりません。

cell1 = Gtk.CellRendererText() 
cell2 = Gtk.CellRendererText() 
combobox.pack_start(cell1, True) 
combobox.pack_start(cell2, True) 
combobox.add_attribute(cell1, "text", 0) 
combobox.add_attribute(cell2, "text", 1) 
関連する問題