Gtk.ListStore(*datatypes) string error

若如初见. 提交于 2020-03-04 08:31:28

问题


self.ip_liststore = Gtk.ListStore(*datatypes)

where

datatypes = [str,str,str]

I have also tried

datatypes = ['gchararray','gchararray']

And the interpreter replies with

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

What happens after the list is unpacked? Are the contents converted to strings? Is there something I don't know about unpacking?


回答1:


I believe there is just a little confusion, and I remember I had a wrong time searching for it.

This is what I do :

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])


来源:https://stackoverflow.com/questions/37712039/gtk-liststoredatatypes-string-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!