Make sure FFI is enabled in your php.ini:
extension=ffi
ffi.enable=trueYou can verify FFI is available:
php -m | grep FFIInstall via Composer:
composer require developersharif/php-guiCreate a file called app.php:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpGui\Application;
use PhpGui\Widget\Window;
use PhpGui\Widget\Label;
use PhpGui\Widget\Button;
// Initialize the application
$app = new Application();
// Create the main window
$window = new Window([
'title' => 'My First PHP GUI App',
'width' => 400,
'height' => 300
]);
// Add a label
$label = new Label($window->getId(), [
'text' => 'Welcome to PHP GUI!'
]);
$label->pack(['pady' => 20]);
// Add a button with a click handler
$button = new Button($window->getId(), [
'text' => 'Click Me',
'command' => function() use ($label) {
$label->setText('You clicked the button!');
}
]);
$button->pack(['pady' => 10]);
// Run the event loop
$app->run();Run your application:
php app.phpWidgets support three layout managers: pack, grid, and place.
Arranges widgets in blocks before placing them in the parent widget:
$label->pack(['side' => 'top', 'pady' => 10, 'padx' => 5]);Places widgets in a 2D grid:
$label->grid(['row' => 0, 'column' => 0]);
$button->grid(['row' => 1, 'column' => 0]);Positions widgets at absolute coordinates:
$label->place(['x' => 50, 'y' => 100]);Most widgets accept styling options:
$button = new Button($window->getId(), [
'text' => 'Styled Button',
'bg' => 'blue',
'fg' => 'white',
'font' => 'Helvetica 16 bold'
]);Common styling options:
bg— Background colorfg— Foreground (text) colorfont— Font specification (family, size, style)relief— Border style (flat,raised,sunken,groove,ridge)padx,pady— Internal padding
Interactive widgets support PHP callbacks:
// Button click
$button = new Button($parent, [
'text' => 'Click',
'command' => function() {
echo "Clicked!\n";
}
]);
// Input enter key
$input = new Input($parent, ['text' => 'Type here...']);
$input->onEnter(function() use ($input) {
echo "Entered: " . $input->getValue() . "\n";
});- Architecture — Learn how the FFI bridge works
- Window — Start with the main window widget
- Full Example — See a complete application