php 图形用户界面GUI 开发
一、下载指定系统扩展
1 2 | http: //pecl.php.net/package/ui http: //pecl.php.net/package/ui/2.0.0/windows |
由于我的系统是64位win10,php版本是7.1,所以选择7.1 Thread Safe (TS) x64,linux用户可以自行下载源码包,编译安装。

解压php_ui-2.0.0-7.1-ts-vc14-x64.zip,把php_ui.dll复制到你php.ini中extension_dir设置的目录,把libui.dll和pthreadVC2.dll复制到C:\Windows\System32目录下。
在php.ini中加入如下:
php_ui.dll ? ? ?--> 放到 ext 目录下 libui.dll ? ? ? --> 放到 php.exe 同级目录作为程序扩展 pthreadVC2.dll ?--> 放到 php.exe 同级目录作为程序扩展 ?
然后重启服务,phpinfo()查看,ui扩展安装成功。
<?php
use UI\Window;
use UI\Size;
use UI\Controls\Entry;
use UI\Controls\Label;
use UI\Controls\Button;
use UI\Controls\Grid;
//创建一个窗口
//参数一表示窗口标题
//参数二表示窗口大小
//参数三表示是否显示菜单
$win =new Window('简单的计算器',new Size(640, 480), true);
//创建一个文本框
//Entry::Normal 普通单行文本框
//Entry::Password 密码框
//Entry::Search 搜索框
$num1 =new Entry(Entry::Normal);
$num2 =new Entry(Entry::Normal);
$ret =new Entry(Entry::Normal);
//创建一个标签
$lab =new Label('+');
//创建一个按钮
$btn =new class('计算')extends Button {
public function __construct($text) {
parent::__construct($text);
}
protected function onClick() {
global $num1,$num2,$ret;
$n1 =$num1->getText();
$n2 =$num2->getText();
$ret->setText($n1 +$n2);
}
};
//创建一个网格
$grid =new Grid();
//把上面的控件加入到网格布局中
$grid->append($num1, 0, 0, 1, 1, true, Grid::Center, false, Grid::Center);
$grid->append($lab, 0, 1, 1, 1, true, Grid::Center, false, Grid::Center);
$grid->append($num2, 0, 2, 1, 1, true, Grid::Center, false, Grid::Center);
$grid->append($btn, 0, 3, 1, 1, true, Grid::Center, false, Grid::Center);
$grid->append($ret, 0, 4, 1, 1, true, Grid::Center, false, Grid::Center);
//把布局加入到窗口中
$win->add($grid);
//显示窗口
$win->show();
UI\run();
?
<?php
use UI\Window;
use UI\Size;
use UI\Controls\Box;
use UI\Controls\Entry;
use UI\Controls\Button;
use UI\Controls\Form;
use UI\Controls\Radio;
use UI\Controls\Check;
use UI\Controls\Combo;
use UI\Controls\MultilineEntry;
//创建一个窗口
//参数一表示窗口标题
//参数二表示窗口大小
//参数三表示是否显示菜单
$win =new Window('简单的计算器',new Size(640, 480), true);
//创建一个表单
$frm =new Form();
//用户名
$user =new Entry(Entry::Normal);
$frm->append('用户名:',$user, false);
//密码
$pwd =new Entry(Entry::Password);
$frm->append('密码:',$pwd, false);
//性别(单选)
$sex =new Radio();
$sex->append("男");
$sex->append("女");
$sex->append("未知");
$frm->append('性别:',$sex, false);
//爱好(多选)
//创建一个盒子,水平排列
$loveBox =new Box(Box::Horizontal);
$love1 =new Check('看书');
$love2 =new Check('旅游');
$love3 =new Check('游戏');
//把多选控件加入盒子中
$loveBox->append($love1);
$loveBox->append($love2);
$loveBox->append($love3);
$frm->append('爱好:',$loveBox, false);
//地区(下拉框)
$area =new Combo();
$area->append("北京");
$area->append("上海");
$area->append("武汉");
$frm->append('地区:',$area, false);
//简介(多行文本)
$desc =new MultilineEntry();
$frm->append('简介:',$desc, false);
//注册按钮
$reg =new class('注册',$win)extends Button {
protected $win;
public function __construct($text,$win) {
$this->win =$win;
parent::__construct($text);
}
//用于重写父类的单击事件
protected function onClick() {
$this->win->msg('消息','你点击了注册按钮');
}
};
$frm->append('',$reg);
$win->add($frm);
//显示窗口
$win->show();
UI\run();

?为了避免每次都要打命令运行php脚本,我们可以写个bat脚本来运行。
D:\amp\php7\php.exe -f D:\wwwroot\demo1\index.php
pause

Fiddlerv5.0.20204.45441? 抓软件??
|