Skip to content

Commit 39c00ff

Browse files
Example file added for dev
1 parent 6a97fe7 commit 39c00ff

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

example.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
require_once __DIR__ . '/vendor/autoload.php';
4+
5+
use PhpGui\Application;
6+
use PhpGui\Widget\Window;
7+
use PhpGui\Widget\Label;
8+
use PhpGui\Widget\Button;
9+
use PhpGui\Widget\Input; // New Input widget
10+
11+
$app = new Application();
12+
13+
// Create main window
14+
$window = new Window([
15+
'title' => 'Hello World Example in php',
16+
'width' => 500,
17+
'height' => 300
18+
]);
19+
20+
// Label Example
21+
$label = new Label($window->getId(), [
22+
'text' => 'Hello, PHP GUI World!'
23+
]);
24+
$label->pack(['pady' => 20]);
25+
26+
// Button Example
27+
$button = new Button($window->getId(), [
28+
'text' => 'Click Me',
29+
'command' => function() use ($label) {
30+
echo "Button clicked!\n";
31+
$label->setText('Button clicked!');
32+
}
33+
]);
34+
$button->pack(['pady' => 10]);
35+
36+
// Extra styled Button example
37+
$styledButton = new Button($window->getId(), [
38+
'text' => 'Styled Button',
39+
'command' => function() use ($label) {
40+
echo "Styled Button clicked!\n";
41+
$label->setText('Styled Button clicked!');
42+
},
43+
'bg' => 'blue',
44+
'fg' => 'white',
45+
'font' => 'Helvetica 16 bold'
46+
]);
47+
$styledButton->pack(['pady' => 10]);
48+
49+
// New Input widget example with extra configuration
50+
$input = new Input($window->getId(), [
51+
'text' => 'Type here...',
52+
'bg' => 'lightyellow',
53+
'fg' => 'black',
54+
'font' => 'Arial 14'
55+
]);
56+
$input->pack(['pady' => 10]);
57+
58+
// Register event listener for Enter key on the input widget
59+
$input->onEnter(function() use ($input) {
60+
echo "Input Enter Pressed: " . $input->getValue() . "\n";
61+
});
62+
63+
// New button to show the input box value on click
64+
$showButton = new Button($window->getId(), [
65+
'text' => 'Show Input',
66+
'command' => function() use ($input) {
67+
echo "Show Input Button clicked: " . $input->getValue() . "\n";
68+
}
69+
]);
70+
$showButton->pack(['pady' => 10]);
71+
72+
$app->run();

0 commit comments

Comments
 (0)