Sample Code 10: How to have a GtkLabel with background color and border?
Written by kksou
Wednesday, 13 September 2006
You want to have a GtkLabel with background color and border as shown below:
- 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
| 1 |
$window = &new GtkWindow();
$window->connect_simple('destroy', array( 'Gtk', 'main_quit'));
// 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');
$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.
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!