我们在这篇文章中将会为大家介绍 PHP GTK写文本查看器代码示例: ?php require_once('File.php'); if (!class_exists('gtk')) { if (strtoupper(substr(PHP_OS, 0,3) == 'WIN')) dl('php_gtk.dll'); else dl('php_gtk.so'); 10 } function delete_event() { return false; } function shutdown() { print("Shutting down"); gtk::main_quit(); } function ButtonLoad_clicked() { SelectFile(); } function ButtonClose_clicked() { global $window; $window->close(); } function fs_OK($button, $fs) { global $TextBox; $TextBox->insert_text (File::readAll($fs->get_filename()), 0); return true; } function fs_Cancel() { return false; } function SelectFile() { $fs = &new GtkFileSelection ('Please select the file'); $ok_button = $fs->ok_button; $ok_button->connect('clicked', 'fs_OK', $fs); $ok_button->connect_object ('clicked', array($fs, 'destroy')); $cancel_button = $fs->cancel_button; $cancel_button->connect ('clicked', 'fs_Cancel'); $cancel_button->connect_object ('clicked', array($fs, 'destroy')); $fs->show(); } $window = &new GtkWindow(); $window->connect( 'destroy', 'shutdown'); $window->connect('delete-event' , 'delete_event'); $window->set_border_width(0); $TextBox = &new GtkText(); $TextBox->set_editable(true); $ButtonLoad = &new GtkButton('Load'); $ButtonLoad->connect('clicked', 'ButtonLoad_clicked'); $ButtonClose = &new GtkButton('Close'); $ButtonClose->connect('clicked', 'ButtonClose_clicked'); $VBox = &new GtkVBox(false, 10); $VBox->pack_start($ButtonLoad); $VBox->pack_start($ButtonClose); $HBox = &new GtkHBox(false, 10); $HBox->pack_start($TextBox); $HBox->pack_start($VBox); $window->add($HBox); $window->show_all(); gtk::main(); ?> 以上代码就是PHP GTK写文本查看器的相关方法介绍。