How can I change color font in GTK2?

R

robertospara

I don't mean Label object but font in Entry or TextView object?
Please for help and thanks from the mountains :)
 
R

robertospara

I am in good direction becouse in C this code would look like this:

gtk_widget_modify_base ( GTK_WIDGET (entry), GTK_STATE_NORMAL,
backgroud);

where background it's a structure of type GdkColor*.

Greetings folks:)

robertospara napisal(a):
 
Z

zentara

I don't mean Label object but font in Entry or TextView object?
Please for help and thanks from the mountains :)


For Entry:
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 '-init';

#the Entry settings in ~/.gtkrc-2.0 dosn't
#seem to do anything except create a subtle outline
#under the entry box. So you need to manually make one.

Gtk2::Rc->parse_string(<<__);

include "/usr/local/share/themes/Bumblebee/gtk-2.0/gtkrc"
style "normal" {
font_name ="serif 30"
}

style "my_entry" {
font_name ="sans 25"
text[NORMAL] = "#FF0000"
}

widget "*" style "normal"
widget "*Entry*" style "my_entry"
__

my $window = Gtk2::Window->new;
$window->set_title("Hello world");
$window->signal_connect( destroy => sub { Gtk2->main_quit; } );

my $vbox = Gtk2::VBox->new();
$vbox->set( "border_width" => 10 );
$window->add($vbox);

my $label = Gtk2::Label->new("??????");
$vbox->pack_start( $label, 0, 0, 5 ); # expand?, fill?, padding

my $entry = Gtk2::Entry->new();
$vbox->pack_start( $entry, 0, 0, 5 );

my $button = Gtk2::Widget->new( "Gtk2::Button", label => "Quit" );
$button->signal_connect( clicked => sub { Gtk2->main_quit; } );

$vbox->pack_start( $button, 0, 0, 5 );

$window->show_all();
Gtk2->main;
__END__

#####################################################3
####################################################

for the textview, the only glitch to watch for is cursor color

#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

Gtk2::Rc->parse_string(<<__);

style "my_text" {
font_name ="sans 24"
text[NORMAL] = "#FFAA00"
base[NORMAL] = "#000000"
GtkTextView::cursor-color = "red"
}

style "my_cursor"{
fg[NORMAL] = "#FF0000"
}

widget "*Text*" style "my_text"
__

my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(400,400);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);

my $ebutton = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $ebutton, FALSE, FALSE, 0 );
$ebutton->signal_connect( clicked => \&delete_event );

# Create a textbuffer to contain that string
my $textbuffer = Gtk2::TextBuffer->new();
$textbuffer->set_text('yadda yadda yadda');

# Create a textview using that textbuffer
my $textview = Gtk2::TextView->new_with_buffer($textbuffer);

# Add the textview to a scrolledwindow
my $scrolledwindow = Gtk2::ScrolledWindow->new( undef, undef );
$scrolledwindow->add($textview);
$vbox->pack_start($scrolledwindow, 1, 1, 0 );

$window->show_all();

Gtk2->main;

#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
#######################################
__END__
 
R

robertospara

This i didn't know. Thanks a lot.
zentara napisal(a):
I don't mean Label object but font in Entry or TextView object?
Please for help and thanks from the mountains :)


For Entry:
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 '-init';

#the Entry settings in ~/.gtkrc-2.0 dosn't
#seem to do anything except create a subtle outline
#under the entry box. So you need to manually make one.

Gtk2::Rc->parse_string(<<__);

include "/usr/local/share/themes/Bumblebee/gtk-2.0/gtkrc"
style "normal" {
font_name ="serif 30"
}

style "my_entry" {
font_name ="sans 25"
text[NORMAL] = "#FF0000"
}

widget "*" style "normal"
widget "*Entry*" style "my_entry"
__

my $window = Gtk2::Window->new;
$window->set_title("Hello world");
$window->signal_connect( destroy => sub { Gtk2->main_quit; } );

my $vbox = Gtk2::VBox->new();
$vbox->set( "border_width" => 10 );
$window->add($vbox);

my $label = Gtk2::Label->new("??????");
$vbox->pack_start( $label, 0, 0, 5 ); # expand?, fill?, padding

my $entry = Gtk2::Entry->new();
$vbox->pack_start( $entry, 0, 0, 5 );

my $button = Gtk2::Widget->new( "Gtk2::Button", label => "Quit" );
$button->signal_connect( clicked => sub { Gtk2->main_quit; } );

$vbox->pack_start( $button, 0, 0, 5 );

$window->show_all();
Gtk2->main;
__END__

#####################################################3
####################################################

for the textview, the only glitch to watch for is cursor color

#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

Gtk2::Rc->parse_string(<<__);

style "my_text" {
font_name ="sans 24"
text[NORMAL] = "#FFAA00"
base[NORMAL] = "#000000"
GtkTextView::cursor-color = "red"
}

style "my_cursor"{
fg[NORMAL] = "#FF0000"
}

widget "*Text*" style "my_text"
__

my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(400,400);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);

my $ebutton = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $ebutton, FALSE, FALSE, 0 );
$ebutton->signal_connect( clicked => \&delete_event );

# Create a textbuffer to contain that string
my $textbuffer = Gtk2::TextBuffer->new();
$textbuffer->set_text('yadda yadda yadda');

# Create a textview using that textbuffer
my $textview = Gtk2::TextView->new_with_buffer($textbuffer);

# Add the textview to a scrolledwindow
my $scrolledwindow = Gtk2::ScrolledWindow->new( undef, undef );
$scrolledwindow->add($textview);
$vbox->pack_start($scrolledwindow, 1, 1, 0 );

$window->show_all();

Gtk2->main;

#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
#######################################
__END__
 
R

robertospara

During working with my program I will change font size and font color.
So I make it like this

# check perldoc Gtk2::Widget & Gtk2::Gdk::Color where color is value
from 0 till 255 (factor is 257)

my ( $red, $green, $blue, $color);

( $red, $green, $blue) = ( 255*257, 255*257, 0);

$color = Gtk2::Gdk::Color->new ( $red, $green, $blue);

entry1->modify_text ( GTK_STATE_NORMAL, $color);

entry1->set_text ('');

zentara napisal(a):
I don't mean Label object but font in Entry or TextView object?
Please for help and thanks from the mountains :)


For Entry:
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 '-init';

#the Entry settings in ~/.gtkrc-2.0 dosn't
#seem to do anything except create a subtle outline
#under the entry box. So you need to manually make one.

Gtk2::Rc->parse_string(<<__);

include "/usr/local/share/themes/Bumblebee/gtk-2.0/gtkrc"
style "normal" {
font_name ="serif 30"
}

style "my_entry" {
font_name ="sans 25"
text[NORMAL] = "#FF0000"
}

widget "*" style "normal"
widget "*Entry*" style "my_entry"
__

my $window = Gtk2::Window->new;
$window->set_title("Hello world");
$window->signal_connect( destroy => sub { Gtk2->main_quit; } );

my $vbox = Gtk2::VBox->new();
$vbox->set( "border_width" => 10 );
$window->add($vbox);

my $label = Gtk2::Label->new("??????");
$vbox->pack_start( $label, 0, 0, 5 ); # expand?, fill?, padding

my $entry = Gtk2::Entry->new();
$vbox->pack_start( $entry, 0, 0, 5 );

my $button = Gtk2::Widget->new( "Gtk2::Button", label => "Quit" );
$button->signal_connect( clicked => sub { Gtk2->main_quit; } );

$vbox->pack_start( $button, 0, 0, 5 );

$window->show_all();
Gtk2->main;
__END__

#####################################################3
####################################################

for the textview, the only glitch to watch for is cursor color

#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

Gtk2::Rc->parse_string(<<__);

style "my_text" {
font_name ="sans 24"
text[NORMAL] = "#FFAA00"
base[NORMAL] = "#000000"
GtkTextView::cursor-color = "red"
}

style "my_cursor"{
fg[NORMAL] = "#FF0000"
}

widget "*Text*" style "my_text"
__

my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(400,400);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);

my $ebutton = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $ebutton, FALSE, FALSE, 0 );
$ebutton->signal_connect( clicked => \&delete_event );

# Create a textbuffer to contain that string
my $textbuffer = Gtk2::TextBuffer->new();
$textbuffer->set_text('yadda yadda yadda');

# Create a textview using that textbuffer
my $textview = Gtk2::TextView->new_with_buffer($textbuffer);

# Add the textview to a scrolledwindow
my $scrolledwindow = Gtk2::ScrolledWindow->new( undef, undef );
$scrolledwindow->add($textview);
$vbox->pack_start($scrolledwindow, 1, 1, 0 );

$window->show_all();

Gtk2->main;

#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
#######################################
__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top