如何设置Gtk2 :: Button的文本颜色? [英] How to set a Gtk2::Button's text colour?

查看:464
本文介绍了如何设置Gtk2 :: Button的文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一种颜色来突出显示一个按钮。然而,modify_fg方法似乎只设置对焦环的颜色。 modify_bg按预期工作。

I am trying to set a colour to highlight a button. However, the modify_fg method only seems to set the focus ring's colour. modify_bg works as expected.

这是我的代码:

use Gtk2 qw/-init/;

my $window = Gtk2::Window->new;
$window->set_title("Window!");

my $button = Gtk2::Button->new("Coloured _button");
# does not affect text
$button->modify_fg(normal => Gtk2::Gdk::Color->new(0xffff, 0, 0));

$window->add($button);
$window->show_all;

Gtk2->main;

我也很感兴趣的是,是否有一种标准的颜色,用户的主题。

I'm also interested whether there is a standard colour for this sort of highlight, to blend in with the user's theme.

推荐答案

你可以获取按钮的子标签并修改其前台,下面是一个例子知道是否有麻烦转换为perl)

you can get the button's child label and modify its foreground, below is an example (python, let me know if there are troubles converting it to perl)

import gtk        

class TestWindow:
    def __init__(self):
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        box = gtk.VBox()

        button0 = gtk.Button("Test Button")
        label0 = button0.get_children()[0]
        label0.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('red'))

        button1 = gtk.Button(stock=gtk.STOCK_ABOUT)
        alignment = button1.get_children()[0]
        hbox = alignment.get_children()[0]
        image, label1 = hbox.get_children()
        label1.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('blue'))

        box.add(button0)
        box.add(button1)

        window.add(box)
        window.set_size_request(200, 200)
        window.show_all()        

    def close_application(self, widget, event, data=None):
        gtk.main_quit()
        return False

if __name__ == "__main__":
    TestWindow()
    gtk.main()

希望这有助于您,

这篇关于如何设置Gtk2 :: Button的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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