GTK example class

By sunslayer on Mar 18, 2011

creates a gui in php with a couple example controls

I couldn't find very many helpful tutorials for GTK, so i hope this helps some people


    class GUI extends GtkWindow {

         * Class constructor
         *  @param int $width       window width
         *  @param int $height      window height
         *  @param int $title       title bar text

        public function __construct($width=400, $height=200, $title="PHP-GTK GUI") {
            // Call parent class constructor

            // Set basic window properties

            // Creates widgets

            // Updates GUI

         * Class destructor
         * Breaks main GTK loop and destroys window

        public function __destruct() {

         * Creates controls used in window

        private function setControls() {

            // Creates new buttons and text label
            $lbl =& new GtkLabel("Hello World!");
            $bOk =& new GtkButton("_Ok");
            $bClose =& new GtkButton("_Close");

            // Bind events to widgets

            // Creates a grid and attaches widgets to it
            $tbl =& new GtkTable(4,2);

            // Adds grid to the window

         * Creates Modal dialog

        public function createDialog() {
            $dialog =& new GtkMessageDialog($this, Gtk::DIALOG_MODAL, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, "PHP-GTK Modal Dialog");
            $dialog->set_markup("<span foreground='blue'>Modal Dialog example</span>");

    if (class_exists("gtk")) { // Checks if GTK module is loaded

        // Creates new instance of class GUI
        new GUI(300,75,"Example Window");

    }   else die("GTK Module not loaded."); // Exit



Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.