PHP写窗体程序

<?php

if(!class_exists('gtk')){ die("NO GTK");}

$wnd=new GtkWindow();

$wnd->set_title("B.B.S.T");

$wnd->connect_simple("destroy",array("gtk","main_quit"));

$lblCredit=new GtkLabel("Please Enter:");

$lblUserName=new GtkLabel("Username:");

$lblPassword=new GtkLabel("Password:");

$txtUserName=new GtkEntry();

$txtPassword=new GtkEntry();

$btnLogin=new GtkButton("_Login");

$btnCancel=new GtkButton("_Cancel");

$tbl=new GtkTable(4,2);

$tbl->attach($lblCredit,0,2,0,1);

$tbl->attach($lblUserName,0,1,1,2);

$tbl->attach($txtUserName,1,2,1,2);

$tbl->attach($lblPassword,0,1,2,3);

$tbl->attach($txtPassword,1,2,2,3);

$tbl->attach($btnCancel,0,1,3,4);

$tbl->attach($btnLogin,1,2,3,4);

$btnLogin->connect_simple("clicked","login",$wnd,$txtUserName,$txtPassword);

$btnCancel->connect_simple("clicked",array($wnd,'destroy'));

function login($wnd,$txtUserName,$txtPassword){

$strUserName=$txtUserName->get_text();

$strPassword=$txtPassword->get_text();

$un='/^\w+$/';

if(preg_match($un,$strUserName) && preg_match($un,$strPassword)){

$wnd->destroy();

} else {

$dialog=new GtkMessageDiaLog($wnd,

Gtk::DIALOG_MODAL,

Gtk::MESSAGE_ERROR,

Gtk::BUTTONS_OK,

"ID or Password Wrong!");

$dialog->set_markup("Wrong Info:\nID or Password Wrong!");

$dialog->run();

$dialog->destroy();

}

}

$wnd->add($tbl);

$wnd->show_all();

Gtk::main();

?>