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:

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 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| <?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
$hbox->pack_start($button, 0); }
$window->show_all(); Gtk::main();
function on_click($button, $arrow_type) { print "You have clicked arrow type: $arrow_type\n"; }
?>
?>
|
Explanation
- Create the arrow.
- Pack the arrow in the button.
- 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. |