It’s My Story!

Desktop programming with PHP!

August 13, 2007 · 1 Comment

php-gtk.gif GTK is an interesting library of php. This library used for desktop application.
Yap! No kidding here. Php is not only using for server side language. We can develop desktop based application also.Recently PHP-GTK2 is released for PHP5 with documentation. A strong forum also developed for developers.I am really exited about it.After installing GTK we can start an example.

<?php

//Step 1
if (!class_exists(’gtk’)) {
die(”Please load the php-gtk2 module in your php.ini”);
}

//Step 2
$wnd = new GtkWindow();

//Step 3
$wnd->set_title(’Hello world’);
$wnd->connect_simple(’destroy’, array(’gtk’, ‘main_quit’));//step 4
$lblHello = new GtkLabel(”Hello world!’”);
$wnd->add($lblHello);

//step 5
$wnd->show_all();
Gtk::main();

?>

This is a sample program for GTK.
Type it in a simple text editor like notepad and save as sample.phpw

It is good practice to check is GTK package available or not. So in first step we should check it.

In second step we make an object of window and in third step we attach the title of the window. In fourth step we add a level to show a message

And in final step we just say the console to display it.

This is the source code of the program now how you should run it.

Don’t be confuse that this is a desktop based application so don’t think about the we server. We will run it there.

To just test you can do a easy way. But before it I am admitting this is not good process. You can copy the source file in your PHP folder and open the dos console. And just go to the file location and run it like other java program( type: C:/wamp/php>php sample.phpw)

If you find the message
“Please load the php-gtk2 module in your php.ini”
it means you did not install GTK2 yet.

Otherwise a window will popup for you. This is amazing.

Categories: PHP

1 response so far ↓

Leave a Comment