2014-03-28 22 views
1

我正在嘗試創建一個簡單的PyGTK組合框。但是,當我運行我的代碼,我得到一個運行時錯誤:創建簡單的PyGTK組合框會導致錯誤

'comboBox = gtk.ComboBox.new_with_model(client_store)' 
AttributeError: type object 'gtk.ComboBox' has no attribute 'new_with_model' 

如何創建一個組合框PyGTK的?這是一個非常複雜的過程來創建我發現這些小部件之一。注意我在Python 2.7上使用PyGTK版本2.24

任何有關如何創建簡單組合框的建議都將不勝感激。

import pygtk 
pygtk.require('2.0') 
import gtk 
gtk.rc_parse('themes/Elegant Brit/gtk-2.0/gtkrc') 

def create_combo_box(self): 

    client_store = gtk.ListStore(str) 

    for f in ("a","b","c"): 
     client_store.append([f]) 

    comboBox = gtk.ComboBox.new_with_model(client_store) # Error occurs here 
    renderer_text = gtk.CellRendererText() 
    comboBox.pack_start(renderer_text, True) 
    comboBox.add_attribute(renderer_text, "text", 0) 
    return comboBox 

回答

0

正如錯誤告訴你,沒有在gtk.ComboBox沒有new_with_model()方法。請參閱documentation。使用comboBox = gtk.ComboBox(model=client_store)

相關問題