Article
Build Cross-Platform Windowed Apps with PHP
Other PHP-GTK Widgets
PHP-GTK has dozens of other widgets that we can instantiate and use in our application. Here's a list:
- GtkButton: A button that can be clicked on.
- GtkCalendar: A calendar that shows dates that can be selected.
- GtkCheckButton: A check box that can be toggled on and off.
- GtkCList: A list with several columns that can be scrolled.
- GtkColorSelection: A very cool widget that can be used to select colors.
- GtkCombo: A dropdown list that can also accept typed in text.
- GtkCTree: A tree list that can contain nodes that can expand and collapse.
- GtkDialog: A popup dialog that can be modal.
- GtkEntry: A text box with text that can be changed.
- GtkFileSelection: Similar to Windows common dialog control, the GtkFileSelection control displays a dialog allowing us to choose a file on our local machine.
- GtkFontSelection: A widget that allows us to select various font properties.
- GtkFrame: A frame that can contain a caption.
- GtkHRuler: A horizontal ruler.
- GtkHScrollBar: A horizontal scrollbar.
- GtkImage: A widget for displaying an image.
- GtkMenu: A container widget that can hold menu items.
- GtkNoteBook: A tabbed control that can display multiple tabs.
- GtkProgressBar: A bar that can be used to display the progress of some event.
- GtkRadioButton: A radio button that can be grouped.
- GtkSpinButton: Used to increment/decrement a value using arrows.
- GtkToolTips: Used to add tooltips to other widgets.
- GtkVBox: Vertical box container.
- GtkVScrollBar: A vertical scrollbar.
- GtkWindow: An application window.
As you can see from the classes shown above, PHP-GTK contains all of the necessary classes to facilitate the development of a complete cross-platform GUI application.
Building a Database App with PHP-GTK
One of the cool things about PHP-GTK is that it integrates seamlessly with PHP, so we can still use all PHP's regular functions in our PHP-GTK applications. The most popular database to use with PHP is MySQL, so let's create a PHP-GTK app that connects to a MySQL database and retrieves some records.
Enter the following commands at the MySQL console application:
create database people;
use people;
create table programmers
(
pId int auto_increment,
pName varchar(50),
pAge tinyint,
primary key(pId),
unique id(pId)
);
Add some people to our programmers' table with the following insert commands:
insert into programmers values(0, 'Bill Smith', 23);
insert into programmers values(0, 'James Black', 45);
insert into programmers values(0, 'Lyonel Jones', 18);
insert into programmers values(0, 'Phil Brown', 22);
insert into programmers values(0, 'Michael Clay', 56);
Now let's create a PHP-GTK app that connects to our database and retrieves the records from our programmers' table. The app is a bit large to post here in its entirety, so download the support material for this article if you want to test it on your machine.