Jump to content

PHP Programming/PHP-GTK

From Wikibooks, open books for an open world

Back to PHP

As you should have already learned in previous sections of this book. PHP is more than just a web server language. It can be used to create GUI applications, shell like scripts, and even daemons, among other things. This chapter focuses on using PHP to create GUI applications using PHP-GTK.


What is PHP-GTK

[edit | edit source]

PHP-GTK is a GTK+ and GNOME language binding for PHP. That's just a fancy way of saying that PHP-GTK makes it so that GNOME and GTK+ programs can be written using PHP.

You have to have PHP-CLI and GTK installed on your box.

For questions, search or browse this PHP GTK Forum hosted by Nabble.

Example PHP-GTK Program

[edit | edit source]

Below is a very simple PHP-GTK program. It just creates a window that doesn't do anything. In fact, as you'll find out if you run it, this window won't even close if you try to close it using the normal means.

<?php
  $window = new GtkWindow();
  $window->show_all();
  gtk::main();
?>

This is a little more complex than your usual Hello World program. But we'll go through it step by step.

The first line:

       $window = new GtkWindow();

creates a new GTK+ window. One thing to note about GTK+ and GNOME programming is that when you create a window it does not automatically get displayed. (That's what the next line does.)

The next line:

       $window->show_all();

displays the newly created window.

The last line:

       gtk::main();

is where all the magic happens with GTK+. For now, just take my word for it that you need to call this to make you GTK+ program run.

[edit | edit source]

Authors Note: This chapter is still un-done. More will be coming later.