我该怎么做?很多网站说我可以在按钮上调用 .modify_bg() ,但这无济于事。我可以向按钮添加一个事件框,并为其添加一个标签,然后更改它的颜色,但它看起来很可怕 - 按钮边缘之间有大量的灰色空间不会改变。我只想要看起来像这样的东西:
(来源:kksou.com)
该网站声称刚刚在按钮上完成了 modify_bg() 。但这对我不起作用。=(。
正确的答案可能涉及创建样式或带有 gtkrc 文件的东西等。有人可以指出我的方向吗?
这是一个小例子:
import gtk
win = gtk.Window()
win.connect("destroy", gtk.main_quit)
btn = gtk.Button("test")
#make a gdk.color for red
map = btn.get_colormap()
color = map.alloc_color("red")
#copy the current style and replace the background
style = btn.get_style().copy()
style.bg[gtk.STATE_NORMAL] = color
#set the button's style to the one you created
btn.set_style(style)
win.add(btn)
win.show_all()
gtk.main()