PHP-GTK2 Newsletter
PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou
Sample Code 253: How to set up clickable link using GtkLinkButton - Part 1 - using signal clicked? |
|
Written by kksou
|
|
Wednesday, 06 June 2007 |
|
Problem You would like to set up a clickable link using the new widget GtkLinkButton available in gtk+2.10 and above as shown below:

Solution
- The link button is a subclass of GtkButton. We use it just like a standard GtkButton.
- Create a link button with the constructor
GtkLinkButton($label).
- To capture button clicks, we register the signal 'clicked' on the link button.
Important Note: This only works for PHP-GTK2 compliled with gtk+ v2.10 and above. If you are using an older version, for linux, you may follow the step-by-step instructions to recompile php-gtk2 with gtk+ v2.10. For windows, please refer to How to install php gtk2 on windows? You may also want to take a look here to see some of the new exciting PHP-GTK2 Functionalities.
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
| <?php $window = new GtkWindow(); $window->set_title($argv[0]); $window->set_size_request(400, 150); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Set up clickable link using GtkLinkButton\n". "Part 1 - using the signal 'clicked'"); $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); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0, 0, 0); $alignment->add($title); $vbox->pack_start($alignment, 0, 0); $vbox->pack_start(new GtkLabel(), 0, 0);
// link button
$hbox = new GtkHBox(); $vbox->pack_start($hbox, false, false); $link_button1 = new GtkLinkButton("manual"); // note 1
$link_button2 = new GtkLinkBUtton("mailing list"); // note 1
$hbox->pack_start(new GtkLabel("Reference: php-gtk2"), false); $hbox->pack_start($link_button1, false); $hbox->pack_start($link_button2, false);
// set up signal handler
$link_button1->connect('clicked', 'on_linkbutton', // 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
- Create the link button.
- Register the signal 'clicked'.
- Note that if you're running this example on linux, please comment out these 3 lines and replace with the system command to launch your favorite browser.
Note
- Note that for a link button, it is a button. And you will see the shape of the button when the cursor is over the button.
- You might want to compare this with the example How to put a clickable link in GtkLabel - Part 2? This one is a clickable label, and you will not see the shape of the button.
Related Links
User reviews Average user ratings: 4.0 (from 1 user) Note: You have to be a registered member to leave a comment. Free registration here. |
|
March 26, 2008 4:46pm