1.2 Display a button
Written by kksou   
Wednesday, 12 March 2008

Objective

Let's use another widget in this example - a button.

Overview

In the previous example, we use GtkLabel to display "Hello World". In this example, we use GtkButton to display a button. The GtkLabel and GtkButton are called widgets in php-gtk. There are many other widgets in such as GtkRadioButton, GtkMenu, GtkTable, including GtkWindow.

  • You will see the same 4 key lines (as explained in the previous example).
  • Now instead of creating a GtkLabel, we create a GtkButton.
  • Then stuff the button inside the window using GtkContainer::add() as before.

Sample Output

1.2.gif

Sample Code

1   
2   
3   
4   
5   
6   
7   
<?php
$window = new GtkWindow();
$window->connect_simple('destroy',array('Gtk','main_quit'));

$button = new GtkButton("click me!"); // note 1
$window->add($button); // note 2

  • 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

For almost all php-gtk2 scripts, you will find the following four key lines (highlighted in blue):

  1. Creates a button.
  2. Add the button to the window.

Note

Think of widgets as different types of Lego building blocks. Some are plain rectangular blocks. Some are round blocks. Some have buttons. By creatively combining these different building blocks, we can build almost anything we have in mind.

Same for php-gtk2. Writing php-gtk2 scripts is all about knowing what are the widgets available, and their corresponding properties, methods and signals.



User reviews

There are no user reviews yet.

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

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved