开发者

How to set a Gtk2::Button's text colour?

开发者 https://www.devze.com 2023-04-01 10:41 出处:网络
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.

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.

This is my code:

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 =开发者_C百科> 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.


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

hope this helps, regards


All previous helped a lot...

All the following works ok!

my $beige = Gtk2::Gdk::Color->new (0xFFFF,0xFFFF,0xCCCC);
my $azul  = Gtk2::Gdk::Color->new (0,0,0xCCCC);
my $rojo  = Gtk2::Gdk::Color->new (0xCCCC,0,0);

$mw->modify_bg ("normal", $beige);

my $butOk = Gtk2::Button->new_with_label(" 
0

精彩评论

暂无评论...
验证码 换一张
取 消