The Window widget is the primary application window. It is always the first widget you create and acts as the $parentId for all other widgets placed inside it. Internally it creates a Tk toplevel window and hooks into the application's quit mechanism.
new Window(array $options = [])Window takes no parent — pass options directly. Default values: title = 'Window', width = 300, height = 200.
| Option | Type | Default | Description |
|---|---|---|---|
title |
string |
'Window' |
Title bar text. |
width |
int |
300 |
Window width in pixels. |
height |
int |
200 |
Window height in pixels. |
use PhpGui\Widget\Window;
$window = new Window([
'title' => 'My App',
'width' => 800,
'height' => 600,
]);After creating the window, use $window->getId() as the $parentId for all child widgets:
use PhpGui\Widget\Label;
$label = new Label($window->getId(), ['text' => 'Hello, World!']);
$label->pack(['pady' => 20]);| Method | Signature | Description |
|---|---|---|
getId() |
(): string |
Returns the unique widget ID (inherited). |
getTcl() |
(): ProcessTCL |
Returns the underlying ProcessTCL instance. |
pack() |
(array $opts): void |
Pack layout (inherited — throws on top-level). |
destroy() |
(): void |
Removes the window from Tk (inherited). |
Note:
pack(),place(), andgrid()will throw aRuntimeExceptiononWindowbecause it has no parent. Use the geometry managers on child widgets only.
- The window registers a
WM_DELETE_WINDOWprotocol handler that calls::exit_app, which signals theApplicationevent loop to stop cleanly. wm deiconifyis called automatically on creation, so the window appears immediately.Windowpassesnullas the parent toAbstractWidget. Its Tk path is.{id}(e.g..w63f1a2b).