PHPackages                             toknot/gtk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. toknot/gtk

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

toknot/gtk
==========

PHP bindings to the GTK+3.

0.1.1(5y ago)12821BSD-3-ClauseCPHP &gt;=7.4.0

Since Mar 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/chopins/php-gtk)[ Packagist](https://packagist.org/packages/toknot/gtk)[ Docs](http://toknot.com)[ RSS](/packages/toknot-gtk/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (1)Versions (3)Used By (0)

php-gtk
-------

[](#php-gtk)

PHP bindings to the [gtk+3](https://www.gtk.org/) C library.

The project only expose GTK API by FFI

**Requirements**

- PHP &gt;= 7.4
- PHP FFI extension available
- toknot/ffi-extend &gt;=0.1

**composer install**

```
composer require toknot/gtk

```

**Status**

- support C function call of `GLib`, `GObject`, `Gio`, `Gtk`, `Atk`, `Gdk`, `Gdk-Pixbuf`, `Pango`
- support C macro value and call of `GLib`,`GLib`, and a small part of `GTK`

**Defined Constants**

DLL file name and header file name map list:

```
class PHPGtk {
    public static $gtkDllMap  = [
        self::GLIB_ID => ['name' => 'libglib', 'header' => ['glib'], 'require_version' => '2.56'],
        self::GIO_ID => ['name' => 'libgio', 'header' => ['gio']],
        self::GOBJECT_ID => ['name' => 'libgobject', 'header' => ['gtype', 'gobject']],
        self::GTK_ID => ['name' => 'libgtk', 'header' => ['gtkfunc']],
        self::GDK_ID => ['name' => 'libgdk', 'header' => ['gdk'], 'require_version' => '3.20'],
        self::PIXBUF_ID => ['name' => 'libgdk_pixbuf', 'header' => ['pixbuf'], 'require_version' => '2.36'],
        self::PANGO_ID => ['name' => 'libpango', 'header' => ['pango'], 'require_version' => '1.42'],
        self::PANGO_CAIRO_ID => ['name' => 'libpangocairo', 'header' => ['pango_cairo']],
        self::ATK_ID => ['name' => 'libatk', 'header' => ['atk'], 'require_version' => '2.28'],
    ];
......
}
```

`Gtk\PHPGtk::$gtkDllMap` determine load dynamic library name prefix and header file.

**Load Dynamic Library**

- In Linux, default find:
    - when `PHP_INT_SIZE` equal 4, OS is 32bit, find `/usr/lib`
    - when `PHP_INT_SIZE` equal 8, OS is 64bit, find `/usr/lib64`
- specify lib path by self through `Gtk\PHPGtk::gtk($libpath)`,
    - if `$libpath` is string, value must be lib directory path
    - will find match $libpath/$name-\*.so, and load the first dll
- specify lib name through set `name` value of specify lib row of `Gtk\APP::$gtkDllMap`

### Usage

[](#usage)

- basic example

    ```
    include dirname(__DIR__) . '/src/PHPGtk.php';
    $gtk = \GTK\PHPGtk::gtk();
    function activate()
    {
        global $gtk, $app;
        try {
        $window = $gtk->gtk_application_window_new($app);
        $gtk->gtk_window_set_title($gtk->GTK_WINDOW($window), "Window");
        $gtk->gtk_window_set_default_size($gtk->GTK_WINDOW($window), 200, 200);
        $gtk->gtk_widget_show_all($window);
        } catch(\Error $e) {
            echo $e;
        }
    }

    function main($argc, $argv) : int
    {
        global $gtk, $app;

        $app = $gtk->gtk_application_new("org.gtk.example", 0);

        $gtk->g_signal_connect($app, "activate", 'activate');

        $gapp = $gtk->G_APPLICATION($app);

        $status = $gtk->g_application_run($gapp, $argc, $argv);

        $gtk->g_object_unref($app);
        return $status;
    }
    return main($argc, $argv);
    ```
- C Lib API call

    - `PHPGtk` class can be call `Gtk`,`GLib`,`GObject`,`Gio`,`Gdk` function
    - `PHPGtk::atk()` return `Gtk\Atk`, can be call `GLib`,`GObject`,`ATK` function
    - `PHPGtk::gdk()` return `Gtk\Pixbuf`, can be call `GLib`, `GObject`, `GIO`, `GDK`,`gdk-pixbuf` function
    - `PHPGtk::pango()` return `Gtk\Pango`, can be call `GLib`,`GObject`,`Pango` function
    - macro value get by same name constant of class
    - macro function call by same name method of class
    - lib version value defined by macro get by global same name constant
    - About gettext of `glib`:
        - `Gtk\Glib::$GETTEXT_PACKAGE` name of `GETTEXT_PACKAGE` when compile `Glib`, default is null
        - `Gtk\Glib::$gettextDll` path of gettext shared library, default is empty, if php eanble gettext, will use php gettext() function instead and the property invaild
    - Gtk\\GtkWidget class provided simple OO method of call C function that related `GtkWidget`

### Note:

[](#note)

- Default, The number of callback function argument must less than 10, otherwise extra argument value always `NULL`, only when `Gtk\GtkAbstract::$gCallbackArgNum` be changed to other value
- if C function for callback, use `GObject::G_CALLBACK($callable)` convert, the `$callable` is smailer `[$gtk, $c_func_name, true]`, it php callable array has 3 entries, 3rd is bool value
- if new C variable be used occur segfault, try new unmanaged variable
- most class is sub of `Gtk\GtkAbstract`

For Windows
-----------

[](#for-windows)

1. get libgtk3 binary DLL file, see
2. copy libgtk3 all DLL file and dependency to your path, if use MSYS install, pass `YOUP_PATH/mingw32/bin` or `YOUP_PATH/mingw64/bin` to `PHPGtk::gtk($libpath)`, if not installed other package,In the path DLL file is libgtk dependency package

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~185 days

Total

2

Last Release

2072d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3683f29364f9fba39ebd7e90377b67c28ca2497e01cefc19ebb40df6cda72ddb?d=identicon)[szopen](/maintainers/szopen)

---

Top Contributors

[![chopins](https://avatars.githubusercontent.com/u/1539465?v=4)](https://github.com/chopins "chopins (109 commits)")

---

Tags

ffigtkgtk3phpphpuiffigtkgtk3

### Embed Badge

![Health badge](/badges/toknot-gtk/health.svg)

```
[![Health](https://phpackages.com/badges/toknot-gtk/health.svg)](https://phpackages.com/packages/toknot-gtk)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
