PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 3: How to set the background color of GtkWindow?
Written by kksou   
Tuesday, 12 September 2006
Problem

You want to set the background color of GtkWindow as follows:

How to set the background color of GtkWindow?


Solution

Use GtkWidget::modify_bg()

$window->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse("#FFFF00"));

Sample Code
1   
2   
3   
4   
5   
6   
7   
<?php
$window = new GtkWindow();
$window->set_size_request(400, 100);
$window->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse("#FFFF00"));
$window->connect_simple('destroy', array('Gtk','main_quit'));
$label = new GtkLabel("hello world!");
$window->add($label);
  • 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 #FFFF00 is the standard hexadecimal color notation, i.e. #RRGGBB.

As for the first argument, they do have quite a bit of explanation in the php manual. But if all you want is to set the background color of the window, just use Gtk::STATE_NORMAL.


Notes

This works with some of the other widgets, but not all.

Some widgets in PHP-GTK2 are "transaparent", meaning they take on the background color of the widgets they are residing in. So using modify_bg does not work. And these transparent widgets happen to be some of the most commonly used ones, including labels and buttons.

Setting the background color of widgets such as labels and buttons requires other techniques. This is covered in "How to set the background color of GtkLabel"


User reviews   Average user ratings:    4.0   (from 5 users)
  1. XeKtRuM
    June 17, 2008 9:22am

  2. niQ from The Netherlands
    August 06, 2008 2:38pm

  3. kirotawa
    September 17, 2008 9:38pm

    great and very easy too

  4. jackywdx
    October 22, 2008 2:22am

  5. martti pitkanen
    March 06, 2009 2:51pm

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved