Page 1 of 1

Beginner's Guide to PHP-GTK Developing GUI apps in PHP has never been so easy! Rate Topic: -----

#1 Moonbat  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 424
  • Joined: 30-June 08

Post icon  Posted 09 October 2008 - 02:33 PM

First off, what IS this PHP-GTK anyway?

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 would I want to make GUI apps in PHP anyway?

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).

How do I get started?

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.

http://gtk.php.net/download.php

Download the latest Windows binary, which, as of now is 2.0.1

http://gtk.php.net/d...1-win32-nts.zip

Once 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:

<?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();
?>


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


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!

Okay... Making little textboxes is cool and all, but I wanna do more!

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!

PHP+GTK2 Cookbook - This gives tons of examples, and is a great place to see how to do a specific task in PHP-GTK
http://www.kksou.com/php-gtk2/

PHP-GTK Documentation - 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)
http://gtk.php.net/docs.php

I hope you've enjoyed this tutorial and learned something! :D
~Moonbat

Is This A Good Question/Topic? 0
  • +

Replies To: Beginner's Guide to PHP-GTK

#2 westforduk  Icon User is offline

  • D.I.C Head

Reputation: 24
  • View blog
  • Posts: 140
  • Joined: 16-August 07

Posted 11 October 2008 - 10:40 AM

I'm going to download now and have a play. :P

Thanks for this. :^:
Was This Post Helpful? 0
  • +
  • -

#3 weldan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-October 08

Posted 12 October 2008 - 09:55 AM

Nice guide. Thanks :D
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Raed*


Reputation:

Posted 02 March 2010 - 05:37 AM

How do we create the executable ??
Was This Post Helpful? 0

Page 1 of 1