<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/widgets/](http://zetcode.com/gui/phpgtktutorial/widgets/) 在 PHP GTK 編程教程的這一部分中,我們將介紹一些小部件。 小部件是 GUI 應用的基本構建塊。 多年來,幾個小部件已成為所有 OS 平臺上所有工具包中的標準。 例如,按鈕,復選框或滾動條。 GTK 工具箱的理念是將小部件的數量保持在最低水平。 將創建更多專門的窗口小部件作為定制 GTK 窗口小部件。 ## `GtkCheckButton` `GtkCheckButton`是具有兩種狀態的窗口小部件:開和關。 接通狀態通過復選標記顯示。 它用來表示一些布爾屬性。 ```php <?php /* ZetCode PHP GTK tutorial This program toggles the title of the window with the GtkCheckButton widget. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } private function init_ui() { $this->set_title('Check button'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $fixed = new GtkFixed(); $this->add($fixed); $cb = new GtkCheckButton("Show title"); $cb->set_active(true); $cb->connect('clicked', array($this, 'on_clicked')); $fixed->put($cb, 50, 50); $this->set_default_size(250, 200); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } public function on_clicked($sender) { if ($sender->get_active()) { $this->set_title("Check button"); } else { $this->set_title(""); } } } new Example(); Gtk::main(); ?> ``` 根據`GtkCheckButton`的狀態,我們將在窗口的標題欄中顯示標題。 ```php $cb = new GtkCheckButton("Show title"); ``` `GtkCheckButton`小部件已創建。 小部件的構造器采用一個參數,即標簽。 標簽顯示在復選框旁邊。 ```php $cb->set_active(true); ``` 默認情況下標題是可見的,因此我們默認情況下選中復選按鈕。 ```php $cb->connect('clicked', array($this, 'on_clicked')); ``` 如果我們單擊復選框小部件,則會發出單擊的信號。 我們將`on_clicked()`方法掛接到信號上。 ```php if ($sender->get_active()) { $this->set_title("Check button"); } else { $this->set_title(""); } ``` 如果選中該按鈕,我們將顯示標題。 `get_active()`方法用于確定檢查按鈕的狀態。 `set_title()`方法用于設置窗口的標題。 為了清除窗口的標題,我們使用一個空字符串。 ![GtkCheckButton](https://img.kancloud.cn/1a/c5/1ac53f95cf6225563cb64bdf568153ce_258x228.jpg) 圖:`GtkCheckButton` ## `GtkLabel` `GtkLabel`小部件顯示文本。 此小部件不支持用戶交互。 ```php <?php /* ZetCode PHP GTK tutorial In this example, we show a text on the window. For this, we use the GtkLabel widget. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } private function init_ui() { // no trailing white space! $lyrics = <<<LYRICS Meet you downstairs in the bar and heard your rolled up sleeves and your skull t-shirt You say why did you do it with him today? and sniff me out like I was Tanqueray cause you're my fella, my guy hand me your stella and fly by the time I'm out the door you tear men down like Roger Moore I cheated myself like I knew I would I told ya, I was trouble you know that I'm no good LYRICS; $this->set_title('GtkLabel'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->set_border_width(10); $label = new GtkLabel($lyrics); $this->add($label); $this->set_default_size(250, 200); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 該代碼示例在窗口上顯示了一些歌詞。 ```php // no trailing white space! $lyrics = <<<LYRICS Meet you downstairs in the bar and heard your rolled up sleeves and your skull t-shirt ``` 我們創建多行文本。 在 PHP 中,可以使用 Heredoc 語法創建多行文本。 ```php $this->set_border_width(10); ``` `GtkLabel`周圍有一些空白。 ```php $label = new GtkLabel($lyrics); $this->add($label); ``` `GtkLabel`小部件已創建并添加到窗口。 ![GtkLabel Widget](https://img.kancloud.cn/4f/72/4f72066544dd07dcb80bd87bb5cbd968_311x286.jpg) 圖:`GtkLabel`小部件 ## `GtkEntry` `GtkEntry`是單行文本輸入字段。 該小部件用于輸入文本數據。 ```php <?php /* ZetCode PHP GTK tutorial This example demonstrates the GtkEntry widget. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { private $label; public function __construct() { parent::__construct(); $this->init_ui(); } private function init_ui() { $this->set_title('GtkEntry'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $fixed = new GtkFixed(); $this->label = new GtkLabel("..."); $fixed->put($this->label, 60, 40); $entry = new GtkEntry(); $fixed->put($entry, 60, 100); $entry->connect('key_release_event', array($this, 'on_key_release')); $this->add($fixed); $this->set_default_size(250, 200); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } public function on_key_release($sender, $event) { $this->label->set_text($sender->get_text()); } } new Example(); Gtk::main(); ?> ``` 此示例顯示了條目小部件和標簽。 我們輸入的文本將立即顯示在標簽小部件中。 ```php $entry = new GtkEntry(); ``` `GtkEntry`小部件已創建。 ```php $entry->connect('key_release_event', array($this, 'on_key_release')); ``` 我們將`on_key_release()`方法插入`GtkEntry`小部件的`key_release_event`。 ```php public function on_key_release($sender, $event) { $this->label->set_text($sender->get_text()); } ``` 在該方法內部,我們通過`get_text()`方法從`GtkEntry`小部件中獲取文本,并使用標簽的`set_text()`方法將其設置為標簽。 ![GtkEntry Widget](https://img.kancloud.cn/a9/ef/a9efa84b0c52985f0b0b185b27dc14b9_258x228.jpg) 圖:`GtkEntry`小部件 ## `GtkImage` `GtkImage`小部件顯示圖像。 ```php <?php /* ZetCode PHP GTK tutorial This example demonstrates the GtkImage widget. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } private function init_ui() { $this->set_title('Red Rock'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->set_border_width(2); $image = GtkImage::new_from_file("redrock.png"); $this->add($image); $this->set_default_size(250, 200); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 在我們的示例中,我們在窗口上顯示圖像。 ```php $this->set_border_width(2); ``` 我們在圖像周圍放置了一些空邊框。 ```php $image = GtkImage::new_from_file("redrock.png"); ``` `GtkImage`小部件已創建。 我們使用靜態`new_from_file()`方法從文件加載圖像。 如果找不到或無法加載文件,則生成的`GtkImage`將顯示損壞的圖像圖標。 ```php $this->add($image); ``` 窗口小部件已添加到容器中。 ## `GtkComboBox` `ComboBox`是一個小部件,允許用戶從選項列表中進行選擇。 ```php <?php /* ZetCode PHP GTK tutorial This example demonstrates the GtkComboBox widget author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { private $label; public function __construct() { parent::__construct(); $this->init_ui(); } private function init_ui() { $this->set_title('GtkComboBox'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $fixed = new GtkFixed(); $this->label = new GtkLabel('-'); $fixed->put($this->label, 50, 140); $cb = GtkComboBox::new_text(); $cb->connect('changed', array($this, 'on_changed')); $cb->append_text('Ubuntu'); $cb->append_text('Mandriva'); $cb->append_text('Redhat'); $cb->append_text('Gentoo'); $cb->append_text('Mint'); $fixed->put($cb, 50, 30); $this->add($fixed); $this->set_default_size(250, 200); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } public function on_changed($sender) { $this->label->set_label($sender->get_active_text()); } } new Example(); Gtk::main(); ?> ``` 該示例顯示了一個組合框和一個標簽。 組合框具有五個選項的列表。 這些是 Linux 發行版的名稱。 標簽窗口小部件顯示了從組合框中選擇的選項。 ```php $cb = GtkComboBox::new_text(); ``` `GtkComboBox`小部件已創建。 `new_text()`是創建僅顯示字符串的`GtkComboBox`的方法。 ```php $cb->append_text('Ubuntu'); $cb->append_text('Mandriva'); $cb->append_text('Redhat'); $cb->append_text('Gentoo'); $cb->append_text('Mint'); ``` 它充滿了數據。 ```php public function on_changed($sender) { $this->label->set_label($sender->get_active_text()); } ``` 在`on_changed()`方法內部,我們從組合框中獲取選定的文本并將其設置為標簽。 ![GtkComboBox](https://img.kancloud.cn/1a/3c/1a3c2bd847651f05a29f825b5395e0c1_258x228.jpg) 圖:`GtkComboBox` 在 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>

                              哎呀哎呀视频在线观看