PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 11: How to change the font color of GtkLabel?
Written by kksou   
Wednesday, 13 September 2006
Problem

You want to change the font color of GtkLabel as shown below:

How to change the font color of GtkLabel?


Solution

Use GtkWidget::modify_fg()

$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse('#366B7E'));

Sample Code
1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
<?php
$window = &new GtkWindow();
$window->connect_simple('destroy', array( 'Gtk', 'main_quit'));
$window->set_size_request(400,200);

// create a vbox to hold multiple labels
$vbox = new GtkVBox();

// create an eventbox that allows you set background color
$eventbox = new GtkEventBox();
$eventbox->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse('#ffff00'));

// create the title label and stuff it in the eventbox
$title = new GtkLabel('This is the title');
$title->set_size_request(100,48);
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse('#366B7E'));  // note 1
$title->modify_font(new PangoFontDescription('Times New Roman Italic 24'));
$vbox->pack_start($eventbox, 0, 0); // note 2
$eventbox->add($title);
  • Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
  • Registration is free and immediate.
  • Have some doubt about the registration? Please read this forum article.
Explanation

The font color of a GtkLabel is changed using modify_fg (note 1).

The font and font size is changed using modify_font (note 2).

 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Links - Classes - Social Business - BPM - Web - General
Copyright © 2006-2013. kksou.com. All Rights Reserved