Warning: unable to set property `editable’ of type `gboolean’ from value of type `gchararray’
做GTK编程的时候,使用TreeView控件时出现这个警告,也就是无法使单元格变为“editable”,原因出在这里:
column = gtk.TreeViewColumn(columName[columnNum], renderer, editable=True)
原理解TreeViewColumn的构造函数接受的参数里面可以接受设置Cellrenderer的属性,就直接给editable设True,于是就得到以上警告。
换用add_attribute、set_attributes,均是如此。
Google上搜到同样错误警告,但是他的原因是设错值类型,我明明设了True啊……
自己观察pygtk-demo的代码和手册,突然发现在构造函数里面给出的属性设置值不应该是直接的值,而是对应Model里面的相应column的值!看手册的描述:
Zero or more attribute=column pairs may be added to specify from which tree model column to retrieve the attribute value.
呃,果然是看手册时候大意了,这么多年来还是让英语介词搞的晕头转向。如果在构造函数里面设True这个值,就会被解析为1,去对应Model里面第二栏的类型,是字符串的gchararray,当然对不上了。
解决办法是renderer.set_property(“editable”, True),调用继承自GObject的set_property方法来设置对象属性。
Warning: unable to set property `text’ of type `gchararray’ from value of type `glong’
遇到这个问题了,搞了一下午没弄清楚。。
大神出个手帮个忙好不。。 unable to set property `text’ of type `gchararray’ from value of type `glong’
这个是我在用一个combobox的控件时出现的问题,pygtk的手册看得头大了也没找到有用的信息
。。。。我没接触gtk很久了,没法给你有用的建议。或者仔细看看是不是像我文章说是设错了对象。