Home arrow PHP arrow Page 2 - Revisited: Building Cross Platform GUI Apps With PHP-GTK

Revisited: Building Cross Platform GUI Apps With PHP-GTK

PHP is not just a web-based scripting language. Did you know that you can also build complete, cross-platform, windowed applications with PHP and MySQL? If not, read on...

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 19
November 17, 2002
  1. · Revisited: Building Cross Platform GUI Apps With PHP-GTK
  2. · What is PHP-GTK?
  3. · Downloading and installing PHP-GTK
  4. · Installing PHP-GTK for Linux
  5. · Building our first PHP-GTK app
  6. · Registering multiple callback functions
  7. · Adding GTK widgets to our window
  8. · Other PHP-GTK widgets
  9. · A PHP-GTK database app
  10. · Conclusion

print this article

Revisited: Building Cross Platform GUI Apps With PHP-GTK - What is PHP-GTK?
(Page 2 of 10 )

Personally, I would call PHP-GTK an excellent set of classes that can be used to build applications containing buttons, windows, toolbars, menus, scroll bars, database access, lists and more. The team that developed PHP-GTK defines it as a PHP extension that allows us to easily write cross-platform GUI based applications.

Funnily enough, PHP-GTK was written to prove that PHP could actually be used to build stuff other than web pages, and let me tell you that they've succeeded.

No doubt you're familiar with the PHP acronym, but what does GTK mean? GTK stands for GIMP tool kit, and it's basically just a set of widgets that we can use to create applications. A widget is the equivalent of a control (such as a button, list box, frame or radio button) in "Linux speak".

GIMP is an acronym for GNU Image Manipulation Program, and is a fully featured graphics editing program that runs on Linux. It has many (if not all) of the features of popular Windows programs such as Photoshop and Paintshop. It's the graphics editor of choice for most Linux users.

GTK is actually part of a set of libraries that was written in C called GTK+. GTK+ was built up over time and is now a main part of Gnome, which is a Linux GUI desktop environment. GTK+ is based on an object-oriented nature and also includes two other libraries:
  1. GLib: A library of tools that can be used to assist developers when creating applications with GTK+.
  2. GDK: Similar to GDI for Win32, GDK standard for GIMP drawing kit and wraps a set of lower level drawing functions into classes that make developing applications with GTK+ easier. If you're thinking along the lines of MFC for C++ then you're making a fair comparison: MFC wraps several controls and hides the calls to the underlying Windows API's from the developer. GDK does the same thing for GTK+.
Although GTK is used in many other applications and projects, in terms of PHP-GTK, it's an advanced set of classes which can be referenced to create widgets which we can then manipulate programmatically. PHP-GTK's programming style is similar to event driven programming languages such as Visual Basic and C++ in that it fires off signals. These signals can be captured and specific functions (called callback functions) can be defined to handle them.

I know that we haven't even looked at PHP-GTK yet, but consider the following PHP code:

$button = &new GtkButton("Click me");

$button->connect("clicked", "buttonClicked");

In the code above I've instantiated a new GtkButton class. I've then called its connect function passing in two parameters: the name of the signal to capture (clicked) as well as the name of a call-back function to execute when this signal is caught (buttonClicked). This tells PHP-GTK that when the button emits a "clicked" signal, that the buttonClicked function should be called.

So if we added a buttonClicked function like this:

function buttonClicked()


echo "You clicked the button";


Then "You clicked the button" would be echoed to the screen when the button is clicked on. That brings me to another point: PHP-GTK apps are run by calling them up with the normal PHP interpreter. The console window in which you called the PHP-GTK GUI app sits in the background and the app sits on top. While the app is running you can still output to the console window using echo, print, etc.

In my opinion this is excellent, because it means that you can set a debug flag and treat the console window as a debug window, outputting debugging statements when you're building your PHP GTK GUI app. When you're ready to distribute the app, simply set the debug flag to false or remove the echo commands.

Well hopefully now you have a bit of an understanding of what PHP-GTK is. The next step is to actually download and install PHP-GTK, so let's do that now.
blog comments powered by Disqus

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials