<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # PHP GTK 中的菜單和工具欄 > 原文: [http://zetcode.com/gui/phpgtktutorial/menustoolbars/](http://zetcode.com/gui/phpgtktutorial/menustoolbars/) 在 PHP GTK 編程教程的這一部分中,我們將使用菜單和工具欄。 GUI 應用中的常見部分是菜單欄。 菜單欄由稱為菜單的對象組成。 頂層菜單在菜單欄上帶有其標簽。 菜單具有菜單項。 菜單項是在應用內部執行特定操作的命令。 菜單也可以具有子菜單,這些子菜單具有自己的菜單項。 ## 簡單菜單 在第一個示例中,我們將創建一個帶有一個文件菜單的菜單欄。 該菜單將只有一個菜單項。 通過選擇項目,應用退出。 ```php <?php /* ZetCode PHP GTK tutorial This example shows a simple menu. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } public function init_ui() { $this->set_title('Simple menu'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->modify_bg(Gtk::STATE_NORMAL, new GdkColor(6400, 6400, 6440)); $mb = new GtkMenuBar(); $filemenu = new GtkMenu(); $filemi = new GtkMenuItem("File"); $filemi->set_submenu($filemenu); $exitmi = new GtkMenuItem("Exit"); $exitmi->connect_simple('activate', array('gtk', 'main_quit')); $filemenu->append($exitmi); $mb->append($filemi); $vbox = new GtkVBox(false, 2); $vbox->pack_start($mb, false, false, 0); $this->add($vbox); $this->set_default_size(250, 200); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 這是一個最小的菜單欄功能示例。 ```php $mb = new GtkMenuBar(); ``` `GtkMenuBar`小部件已創建。 這是各個菜單的容器。 ```php $filemenu = new GtkMenu(); $filemi = new GtkMenuItem("File"); $filemi->set_submenu($filemenu); ``` 創建頂層`GtkMenuItem`。 菜單項代表 GUI 應用中的操作。 ```php $exitmi = new GtkMenuItem("Exit"); $exitmi->connect_simple('activate', array('gtk', 'main_quit')); $filemenu->append($exitmi); ``` 將創建出口`GtkMenuItem`,并將其附加到文件`GtkMenuItem`中。 ```php $mb->append($filemi); ``` 頂級`GtkMenuItem`被附加到`GtkMenuBar`小部件。 ```php $vbox = new GtkVBox(false, 2); $vbox->pack_start($mb, false, false, 0); ``` 與其他工具包不同,我們必須自己照顧菜單欄的布局管理。 我們將菜單欄放入垂直框中。 ![Simple menu](https://img.kancloud.cn/34/b5/34b54539d88ec8160efc9f810bc6760e_258x228.jpg) 圖:簡單菜單 ## 子菜單 我們的最后一個示例演示了如何創建子菜單。 子菜單是另一個菜單中的菜單。 ```php <?php /* ZetCode PHP GTK tutorial This example shows a submenu. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } public function init_ui() { $this->set_title('Submenu'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->modify_bg(Gtk::STATE_NORMAL, new GdkColor(6400, 6400, 6440)); $mb = new GtkMenuBar(); $filemenu = new GtkMenu(); $filemi = new GtkMenuItem("File"); $filemi->set_submenu($filemenu); $mb->append($filemi); $imenu = new GtkMenu(); $importm = new GtkMenuItem("Import"); $importm->set_submenu($imenu); $inews = new GtkMenuItem("Import news feed..."); $ibookmarks = new GtkMenuItem("Import bookmarks..."); $imail = new GtkMenuItem("Import mail..."); $imenu->append($inews); $imenu->append($ibookmarks); $imenu->append($imail); $filemenu->append($importm); $exitmi = new GtkMenuItem("Exit"); $exitmi->connect_simple('activate', array('gtk', 'main_quit')); $filemenu->append($exitmi); $vbox = new GtkVBox(false, 2); $vbox->pack_start($mb, false, false, 0); $this->add($vbox); $this->set_default_size(320, 250); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 子菜單創建。 ```php $imenu = new GtkMenu(); ``` 子菜單是常規`GtkMenu`。 ```php $importm = new GtkMenuItem("Import"); $importm->set_submenu($imenu); ``` 它是菜單項的子菜單,它會登錄到頂級文件菜單。 ```php $inews = new GtkMenuItem("Import news feed..."); $ibookmarks = new GtkMenuItem("Import bookmarks..."); $imail = new GtkMenuItem("Import mail..."); $imenu->append($inews); $imenu->append($ibookmarks); $imenu->append($imail); ``` 子菜單有其自己的菜單項。 ![Submenu](https://img.kancloud.cn/7c/28/7c28c16c8051eb598b45b1fd29c92d23_328x278.jpg) 圖:子菜單 ## 圖像菜單 在下一個示例中,我們將進一步探索菜單。 我們將圖像和加速器添加到我們的菜單項中。 加速器是用于激活菜單項的鍵盤快捷鍵。 ```php <?php /* ZetCode PHP GTK tutorial This example shows a menu with images, accelerators and a separator. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } public function init_ui() { $this->set_title('Image menu'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->modify_bg(Gtk::STATE_NORMAL, new GdkColor(6400, 6400, 6440)); $mb = new GtkMenuBar(); $filemenu = new GtkMenu(); $filemi = new GtkMenuItem("File"); $filemi->set_submenu($filemenu); $mb->append($filemi); $agr = new GtkAccelGroup(); $this->add_accel_group($agr); $newi = new GtkImageMenuItem(Gtk::STOCK_NEW, $agr); $newi->add_accelerator('activate', $agr, Gdk::KEY_N, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE); $newi->connect_simple('activate', array($this, 'on_new_selected')); $filemenu->append($newi); $openmi = new GtkImageMenuItem(Gtk::STOCK_OPEN, $agr); $openmi->add_accelerator('activate', $agr, Gdk::KEY_O, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE); $filemenu->append($openmi); $sep = new GtkSeparatorMenuItem(); $filemenu->append($sep); $exitmi = new GtkImageMenuItem(Gtk::STOCK_QUIT, $agr); $exitmi->add_accelerator('activate', $agr, Gdk::KEY_Q, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE); $exitmi->connect_simple('activate', array('gtk', 'main_quit')); $filemenu->append($exitmi); $vbox = new GtkVBox(false, 2); $vbox->pack_start($mb, false, false, 0); $this->add($vbox); $this->set_default_size(320, 250); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } public function on_new_selected() { print "new"; } } new Example(); Gtk::main(); ?> ``` 我們的示例顯示了具有三個子菜單項的頂級菜單項。 每個菜單項都有一個圖像和一個加速器。 退出菜單項的加速器退出應用。 新菜單項的加速器將`"new"`打印到控制臺。 ```php $agr = new GtkAccelGroup(); $this->add_accel_group($agr); ``` 要使用加速器,我們創建一個全局`GtkAccelGroup`對象。 稍后將使用。 ```php $newi = new GtkImageMenuItem(Gtk::STOCK_NEW, $agr); $newi->add_accelerator('activate', $agr, Gdk::KEY_N, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE); $newi->connect_simple('activate', array($this, 'on_new_selected')); $filemenu->append($newi); ``` 創建了`GtkImageMenuItem`。 圖片來自圖片庫。 我們還創建了 `Ctrl + N` 加速器。 當我們用鼠標選擇菜單項或按下加速器時,一條消息會打印到控制臺上。 ```php $sep = new GtkSeparatorMenuItem(); $filemenu->append($sep); ``` 這些行創建一個分隔符。 它用于將菜單項放入邏輯組。 ![Image menu](https://img.kancloud.cn/64/62/6462695de9e9129114eae9a5db67ffc6_328x278.jpg) 圖:圖像 menu 菜單將我們可以在應用中使用的命令分組。 使用工具欄可以快速訪問最常用的命令。 ## 簡單的工具欄 接下來,我們創建一個簡單的工具欄。 工具欄提供對應用最常用功能的快速訪問。 ```php <?php /* ZetCode PHP GTK tutorial This example shows a toolbar widget. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } public function init_ui() { $this->set_title('Toolbar'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $toolbar = new GtkToolbar(); $toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS); $newtb = GtkToolButton::new_from_stock(Gtk::STOCK_NEW); $opentb = GtkToolButton::new_from_stock(Gtk::STOCK_OPEN); $savetb = GtkToolButton::new_from_stock(Gtk::STOCK_SAVE); $sep = new GtkSeparatorToolItem(); $quittb = GtkToolButton::new_from_stock(Gtk::STOCK_QUIT); $toolbar->insert($newtb, 0); $toolbar->insert($opentb, 1); $toolbar->insert($savetb, 2); $toolbar->insert($sep, 3); $toolbar->insert($quittb, 4); $quittb->connect_simple("clicked", array('Gtk', 'main_quit')); $vbox = new GtkVBox(false, 2); $vbox->pack_start($toolbar, false, false, 0); $this->add($vbox); $this->set_default_size(250, 200); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 該示例顯示了一個工具欄和四個工具按鈕。 ```php $toolbar = new GtkToolbar(); ``` `GtkToolbar`小部件已創建。 ```php $toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS); ``` 在工具欄上,我們僅顯示圖標。 沒有文字。 ```php $newtb = GtkToolButton::new_from_stock(Gtk::STOCK_NEW); ``` 創建帶有庫存圖像的`GtkToolButton`。 該圖像來自圖像的內置庫存。 ```php $sep = new GtkSeparatorToolItem(); ``` 這是一個分隔符。 它可用于將工具欄按鈕放入邏輯組。 ```php $toolbar->insert($newtb, 0); $toolbar->insert($opentb, 1); ... ``` 工具欄按鈕插入到工具欄小部件中。 `insert()`方法的第一個參數是工具按鈕。 第二個是工具欄上的位置。 ![Toolbar](https://img.kancloud.cn/aa/8e/aa8e605e341ddd9aa0e94713679f6ffd_258x228.jpg) 圖:工具欄 在 PHP GTK 教程的這一章中,我們展示了如何使用菜單和工具欄。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看