PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 1: How to get started?
Written by kksou   
Tuesday, 12 September 2006
Problem

How to get started in PHP-GTK2?

As with many other programming languages, let start with this simple yet complete "hello world!" PHP-GTK2 example as shown below:

How to get started?


Solution

Do take some time to understand this simple yet complete "hello world!" PHP-GTK2 script.

Once you understand this script, you are on your way to picking up other widgets one by one and add onto this script.


Sample Code
1   
2   
3   
4   
5   
<?php
$window = new GtkWindow();
$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
  1. new GtkWindow() creates a new window.
  2. connect('destroy', array('Gtk','main_quit')) ensures a clean exit when you close the window. This basically says call Gtk::main_quit() when the user close the window.
  3. new GtkLabel("hello world!") creates the text string as label.
  4. And we use $window->add to place the label in the window.
  5. $window->show_all() shows the window and all its contents.
  6. Gtk::main() - GTK takes over and starts waiting for events (e.g. mouse or keyboard input).

User reviews   Average user ratings:    4.0   (from 37 users)
  1. Yann from France
    March 01, 2008 9:52am

  2. Richard
    March 03, 2008 4:19pm

  3. Benjie Lin
    March 24, 2008 5:07pm

  4. Sebastian Gebhard
    April 02, 2008 12:15am

  5. clusk
    April 03, 2008 9:32am

  6. Nikolai
    April 29, 2008 1:01am

  7. test
    May 03, 2008 3:20am

  8. bugmenot
    May 12, 2008 7:31am

  9. chandrasen shukla
    June 02, 2008 10:11pm

  10. XeKtRuM
    June 17, 2008 8:54am

  11. henry
    July 09, 2008 7:14pm

  12. minus
    July 10, 2008 10:52am

  13. Vad Viktor
    July 22, 2008 2:21am

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

  15. Dmitriy Donda
    August 26, 2008 9:47pm

  16. izi
    October 07, 2008 4:48am

  17. Rizwan
    October 14, 2008 1:21am

  18. kvravikiran
    October 20, 2008 2:21am

  19. jackywdx
    October 22, 2008 1:49am

  20. Klaus Frank
    October 23, 2008 1:47pm

  21. udeep krishna shrestha
    November 05, 2008 11:59pm

  22. Ionut
    February 12, 2009 4:54am

  23. anoop kumar
    February 13, 2009 9:09pm

  24. martti pitkanen
    March 06, 2009 2:47pm

  25. Istvan
    March 12, 2009 1:29am

  26. maxline
    April 13, 2009 5:55am

  27. richard noromor
    April 22, 2009 11:34am

  28. Patrick Bielen
    June 02, 2009 2:24am

  29. ejwalk
    June 23, 2009 7:37am

  30. Ramkrishna
    June 28, 2009 12:48am
    Unknown

    Unknown

  31. Dennis Andres
    August 05, 2009 9:53am

  32. deepa
    November 09, 2009 5:33am

    good

  33. PsYhLo
    January 21, 2010 11:58pm

  34. Rupesh
    April 19, 2010 6:21am

  35. suresh
    May 23, 2010 10:41pm
    sample

    Class 'GtkWindow' not found

  36. anumaster
    June 21, 2010 8:07pm

  37. crasybt
    August 05, 2010 11:23pm
    very good

    This is a very good file!

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

 
Next >

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