Python 3.x 修改PyGObject中所有TreeView项的背景
我想在Python 3.x 修改PyGObject中所有TreeView项的背景,python-3.x,gtk,pygobject,Python 3.x,Gtk,Pygobject,我想在Gtk.TreeView中为我的项目设置(默认)不同的颜色。下面的示例代码无效。背景保持白色 #!/usr/bin/env python3 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gdk class MyTree(Gtk.TreeView): def __init__(self): Gtk.TreeView
Gtk.TreeView
中为我的项目设置(默认)不同的颜色。下面的示例代码无效。背景保持白色
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
class MyTree(Gtk.TreeView):
def __init__(self):
Gtk.TreeView.__init__(self)
# color
color = Gdk.RGBA(221, 29, 157, 1)
# model
model = Gtk.TreeStore(int)
for i in range(4):
model.append(None, [i])
self.set_model(model)
# column
ren = Gtk.CellRendererText(background_set=True,
background_rgba=color)
col = Gtk.TreeViewColumn('int', ren)
col.add_attribute(ren, 'text', 0)
self.append_column(col)
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
tree = MyTree()
self.add(tree)
self.connect('destroy', Gtk.main_quit)
if __name__ == '__main__':
win = MyWindow()
win.show_all()
Gtk.main()
这只是一个“错误”。我使用了Gdk.RGBA()
错误的方法。其参数仅在0.0
和1.0
之间有效
color = Gdk.RGBA(.2, .9, .15, 1)
这只是一个“错误”。我使用了Gdk.RGBA()
错误的方法。其参数仅在0.0
和1.0
之间有效
color = Gdk.RGBA(.2, .9, .15, 1)