GTK:创建一个彩色的常规按钮 [英] GTK: create a colored regular button

查看:349
本文介绍了GTK:创建一个彩色的常规按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该怎么办?很多网站说我可以在按钮上调用.modify_bg(),但是没有做任何事情。我可以添加一个EventBox到按钮,并添加一个标签,然后改变它的颜色,但它看起来可怕 - 按钮的边缘之间有一吨的灰色空间不会改变。我只想要这样的东西:

How do I do it? A lot of sites say I can just call .modify_bg() on the button, but that doesn't do anything. I'm able to add an EventBox to the button, and add a label to that, and then change its colors, but it looks horrendous - there is a ton of gray space between the edge of the button that doesn't change. I just want something that looks like this:

网站声称刚刚在按钮上做了modify_bg()。但这不适用于我。 =(。

The site claims to have just done modify_bg() on the button. But that doesn't work for me. =(.

正确的答案可能涉及创建风格或带有gtkrc文件的东西等。有人可能指向这个方向吗?

The right answer probably involves creating a style, or something with a gtkrc file, etc. Can someone point me in that direction?

推荐答案

这里有一个例子:

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

这篇关于GTK:创建一个彩色的常规按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆