Posted 09 October 2008 - 02:33 PM

<?php // Create the window $window = new GtkWindow(); // This insures a clean exit when the app is closed $window->connect_simple("destroy", array('Gtk', 'main_quit')); // Labels can be text. This one is just a simple sentence $label = new GtkLabel("Testing PHP GTK 1 2 1 2"); // Here we are changing the size of the window to 100x100 $window->set_size_request(100, 100); // The label is being added to the window, so you wil see // the text in the our previous label inside the window $window->add($label); // This actually will display the window to us $window->show_all(); // This keeps the window displayed (like a loop) and it is required Gtk::main(); ?>

It is an application programming interface (API) that allows you to develop GUI applications using PHP and it's object-oriented programming concepts. It uses the The GIMP Toolkit, created by the makers of the popular graphics editor GIMP.Why not? PHP is already widely known as a web language used in developing web applications, and it is also used as a scripting language on the command line. It's fun for a PHP programmer to be able to create GUI applications with PHP. And all programmers program for fun (well, they should, at least).First, let's assume you are using Windows have PHP installed in C:\php. Now, let's visit the PHP-GTK website, specifically the download page.Download the latest Windows binary, which, as of now is 2.0.1Once you've downloaded it, extract the folder named php-gtk2 to C:\php. Your directory path should look like C:\php\php-gtk2.Now, create a .php file named test.php inside of the php-gtk2 folder. Put this code inside of the folder:Now, open up Command Prompt. Go to Start, then find the Run button. Click it, and type 'cmd' without the quotes into the box. The Command Prompt box should come up, in all of it's dark and ill-foreboding glory.Use the 'cd' command to change your current working directory (CWD) to C:\php\php-gtk2. Then type this:

Quote

php test.php

PHP+GTK2 Cookbook

PHP-GTK Documentation

A simple 150x100 textbox should appear with the words "Testing PHP GTK 1 2 1 2". Congratulations, you've made your first GUI application in PHP!I'm afraid I cannot cover all aspects of PHP-GTK here. There's a limitless amount of things that can be done with PHP-GTK, and if I went over them all here, this would change from a tutorial into a PHP-GTK user manual. But don't fret, because below I've given the best resources on PHP-GTK that Google can find!- This gives tons of examples, and is a great place to see how to do a specific task in PHP-GTK- If at first you don't succeed, read, read the documentation. Not to mention the search bar at the top of the page allows you to search for a specific function (just like the PHP.NET website)I hope you've enjoyed this tutorial and learned something!~Moonbat