[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: How can I draw colorful characters on Gtk2::Button?
- From: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
- To: xu zhou <redicaps gmail com>
- Cc: gtk-perl-list gnome org
- Subject: Re: How can I draw colorful characters on Gtk2::Button?
- Date: Thu, 26 Mar 2009 07:35:20 +0100
On Thu, Mar 26, 2009 at 7:02 AM, xu zhou
<redicaps gmail com> wrote:
Hi all, I am quite a new for Perl-Gtk2. I am tring to put some
colorful numbers on the button widget.
$button->set_label($style) dose not seem to work this way, it only
receive a string as the parameter, not a Gtk2::Lable.
The Gtk2::Button is a Gtk2::Bin which means you can call get_child() on a button and get the button's label. Once you get the label you can use set_markup() to colorize your text. To add a label to the button either use the constructor new_with_label() or create the label manually and add it with add().
I've attached a sample perl program that shows how to colorize a button.
--
Emmanuel Rodriguez
#!/usr/bin/perl
#
# Create a button with colorized text
#
use strict;
use warnings;
use Glib qw(TRUE FALSE);
use Gtk2 '-init';
use Data::Dumper;
exit main();
sub main {
my $window = Gtk2::Window->new();
my $vbox = Gtk2::VBox->new(FALSE, 10);
my $button_plain = Gtk2::Button->new_with_label("Plain");
# Create a color with an empty label and replace the label's text with our own
# pretty colored text.
my $button_color = Gtk2::Button->new_with_label('');
$button_color->get_child->set_markup(
"<span color='red'>Color</span> <span color='blue'>button</span>"
);
$vbox->pack_start($button_plain, FALSE, FALSE, 10);
$vbox->pack_start($button_color, FALSE, FALSE, 10);
$window->add($vbox);
$window->signal_connect(destroy => sub {
Gtk2->main_quit();
});
$window->show_all();
Gtk2->main();
return 0;
}
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]