一、下载指定系统扩展
由于我的系统是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的ext目录中,然后php.ini加入extension=php_ui.dll
- pthreadVC2.dll和libui.dll放入php目录中,也就是和php.exe文件同级
- cmd中运行php -m命令查看模块有没有正确加载
然后重启服务,phpinfo()查看,ui扩展安装成功。
二、我们创建一个简单的计算器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?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);
$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脚本
运行结果如下:
三、我们创建一个常用的注册表单
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<?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脚本来运行。
1
2
|
D:\amp\php7\php.exe -f D:\wwwroot\demo1\index.php
pause
|
注意php.exe的路径和运行脚本路径,保存为run.bat,运行结果如下:
参考 https://www.cnblogs.com/jkko123/p/7873024.html
https://segmentfault.com/a/1190000011513423
一、下载指定系统扩展
由于我的系统是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的ext目录中,然后php.ini加入extension=php_ui.dll
- pthreadVC2.dll和libui.dll放入php目录中,也就是和php.exe文件同级
- cmd中运行php -m命令查看模块有没有正确加载
然后重启服务,phpinfo()查看,ui扩展安装成功。
二、我们创建一个简单的计算器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?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);
$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脚本
运行结果如下:
三、我们创建一个常用的注册表单
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<?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脚本来运行。
1
2
|
D:\amp\php7\php.exe -f D:\wwwroot\demo1\index.php
pause
|
注意php.exe的路径和运行脚本路径,保存为run.bat,运行结果如下:
参考 https://www.cnblogs.com/jkko123/p/7873024.html
https://segmentfault.com/a/1190000011513423
|
请发表评论