From Code Trash
Jump to: navigation, search

PHP-GTK is a set of language bindings for PHP which allow GUI applications to be written in PHP.

Here you can find some code examples and explanation.

The following are excerpts from many sources and some are my sentences

Install PHP-GTK

  • PHP-GTK comes in various forms. Mostly as a self extractor with which you can extract the files on any location of your computer. Google it and you will get.
  • You can use any text editor to create a php-gtk program. I use dreamweaver so that i can check the syntax. Choosing an editor is left to you. You can select one from google.
  • Save the source code anywhere. Right click on that file and select open with to bring a dialog box using which you can select the gtk interpreter which displays the output. Browse to the location where you extracted the gtk binaries and select php-win.exe and click ok. Todyng... you got it.

Create a window

if (!class_exists('gtk')) {
dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));
/*Now, create the window widget as a variable.*/
$window = &new GtkWindow();
/*Next, create a title for this new window widget.*/
$window->set_title("My first php gtk program");
/*Then you will set the widget window to the center of the screen.*/
/*Set width and height of the window*/
$window->connect_simple('destroy', array('gtk', 'main_quit'));
/*Attach event to quit the process when uses clicks close button
 which will close the window and the process*/
/* Run the program from top to bottom. */

Here is a good explanation for a simple hello world program

Signal & Event Handling

In php gtk there are signals and events which are not the same. In other languages i have seen only events. Anyway here is a good resource for signal and event handling. go through all the links in this page and you would get more information about the meaning and usage of signals and events.

My Experiments

Here you can find some of the classes and its examples which i have used for my purpose which will not have all of the classes and functions.

PHP-GTK GtkFileSelection function


  • It is possible that some errors crept in. Please do inform the PHP-GTK documentation group'': at in case you encounter such errors.