self.ip_liststore = Gtk.ListStore(*datatypes)
,其中
datatypes = [str,str,str]
我也试过
datatypes = ['gchararray','gchararray']
翻译回复
Traceback (most recent call last):
File "./gtktutorial.py", line 128, in <module>
main()
File "./gtktutorial.py", line 119, in main
[str,str,str,str,str,str,str])
File "./gtktutorial.py", line 37, in __init__
self.ip_liststore = Gtk.ListStore(*datatypes)
File "/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py", line 943, in __init__
self.set_column_types(column_types)
TypeError: Item 0: Must be gobject.GType, not str
解压缩列表后会发生什么?内容是否转换为字符串?有什么我不知道拆箱的事吗?
答案 0 :(得分:0)
我相信只会有一点混乱,我记得我在寻找它时遇到了错误的时间。
这就是我的所作所为:
self.searchCols = ["Object", "Index", "Date", "Program", "Person", "Mode"]
sequence = [str] * len(self.searchCols)
self.resultStore = gtk.ListStore( * sequence )
self.resView = gtk.TreeView(self.resultStore)
self.resView.cell = [None] * len(self.searchCols)
rvcolumn = [None] * len(self.searchCols)
for colnum, col in enumerate ( self.searchCols ) :
self.resView.cell[colnum] = gtk.CellRendererText()
rvcolumn[colnum] = gtk.TreeViewColumn(col, self.resView.cell[colnum])
rvcolumn[colnum].add_attribute(self.resView.cell[colnum], 'text', colnum)
self.resView.append_column(rvcolumn[colnum])