PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 364: How to display buttons with arrows?
Written by kksou   
Tuesday, 13 November 2007
Problem

Suppose you would like to display some buttons with arrows as shown below:

How to display buttons with arrows?

For windows users, you would like to see the stock images too.


Solution

Sample Code
1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
22   
23   
24   
25   
26   
27   
28   
29   
30   
31   
<?php
$window = new GtkWindow();
$window->set_size_request(400, 150);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

// display title
$title = new GtkLabel("Display buttons with arrows");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 40);
$vbox->pack_start($title, 0, 0);
$vbox->pack_start(new GtkLabel(), 0, 0);

$arrow_label = array('up', 'down', 'left', 'right');
$arrow_type = array(Gtk::ARROW_UP, Gtk::ARROW_DOWN, Gtk::ARROW_LEFT, 
    Gtk::ARROW_RIGHT); // note 3

$hbox = new GtkHBox();
$hbox->pack_start(new GtkLabel('Click any of the arrow buttons: '), 0);
$vbox->pack_start($hbox, 0);

for($i=0; $i<4; ++$i) {
    $button = new GtkButton(); // create a standard button
    $button->connect('clicked', 'on_click', $arrow_label[$i]);
    $button_hbox = new GtkHBox();
    $button->add($button_hbox);

    $arrow = new GtkArrow($arrow_type[$i], Gtk::SHADOW_NONE); // note 1
    $button_hbox->pack_start($arrow); // 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
  1. Create the arrow.
  2. Pack the arrow in the button.
  3. Note the different arrow types available in PHP-GTK2.

Related Links

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 >

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