Re: how to set gtk global font with code?



On Mon, 15 Jan 2007 12:42:59 +0000
Chris Vine <chris cvine freeserve co uk> wrote:

>On Wednesday 10 January 2007 03:27, lonelycat wrote:
>>   Hi all:
>>
>>  Can anyone tell me how to set gtk global font with code instead of editing
>> gtkrc file?
>
>GtkSettings has a "gtk-font-name" property representing the default font used 
>by the application.  You can extract the settings object with 
>gtk_settings_get_default() and then set the property on it.
>
>Chris

This also works:

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

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

style "default"                                                                           
{                                                                                         
font_name = "adobe courier bold 30"                                                       
}
widget "*" style "default"
__

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('Big Font');
$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 => \&my_quit );
$vbox->pack_start( $button, 0, 0, 5 );

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

sub my_quit { print "Yee Haw!\n";
    exit;
}

__END__


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]