PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 10: How to have a GtkLabel with background color and border?
Written by kksou   
Wednesday, 13 September 2006
Problem

You want to have a GtkLabel with background color and border as shown below:

How to have a GtkLabel with background color and border?


Solution
  • Create a GtkEventBox
  • Place the label in the EventBox
  • Set the background color of the eventbox with modify_bg
  • Then create a GtkFrame
  • Stuff the EventBox inside the Frame
  • Set the color of the frame with modify_bg

Sample Code
1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
<?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')); // note 1

// create the title label and stuff it in the eventbox
$title = new GtkLabel('This is the title');
$title->set_size_request(100,48);
$eventbox->add($title); // note 2

// create a frame to act as border
$frame = new GtkFrame();
$frame->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse('#0000ff')); // note 3
$frame->add($eventbox); // note 4
  • 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

Please take a look at the following two articles if you haven't:

Note 1: creates an eventbox and sets its background to yellow.

Note 2: place the title inside the eventbox.

Note 3: creates a frame and sets its border to blue.

Note 4: stuff the eventbox inside the frame. Now you have a label with yellow background and blue border!

 

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