AttributeError:'MyWindow'对象没有'on_name_combo_changed'属性

时间:2016-12-07 18:19:48

标签: python combobox gtk3

Dim mySQLCommnad as IngresCommand 
'NB I am using Ingres, but this will need to relate to whichever database flavor you are using.

mySQLCommand = myVector.myIngresConnection.CreateCommand()
mySQLCommand.CommandText = My.Resources.Extract
mySQLCommand.Parameters.Add("@startdate", SqlDbType.Date).Value = dtStart.Text
mySQLCommand.Parameters.Add("@enddate", SqlDbType.Date).Value = dtEnd.Text

'RunSQL
...

嘿伙计们我是python的新手,但我对此错误感到困惑。我已经按照教程和文档进行了操作,但我似乎无法解决这个问题。我无法弄清楚为什么它说它没有属性,即使我在“自我”之后提到它。

1 个答案:

答案 0 :(得分:0)

您必须在班级中创建方法on_name_combo_changed(self, widget)

from gi.repository import Gtk

class MyWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Grid example")

        self.connect("delete-event", Gtk.main_quit)

        grid = Gtk.Grid()
        self.add(grid)

        #combobox
        devices_list = Gtk.ListStore(int, str)
        devices_list.append([1, "Device 1"])
        devices_list.append([2, "Device 2"])

        name_combo = Gtk.ComboBox.new_with_model_and_entry(devices_list)
        name_combo.connect("changed", self.on_name_combo_changed)
        name_combo.set_entry_text_column(1)
        grid.attach(name_combo, 5, 0, 2, 1)

        self.show_all()

    def on_name_combo_changed(self, widget):
        print('ComboBox:', widget)


app = MyWindow()
Gtk.main()

Python GTK + 3教程:13. ComboBox