<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # PyGTK 中的小部件 > 原文: [http://zetcode.com/gui/pygtk/widgets/](http://zetcode.com/gui/pygtk/widgets/) 在 PyGTK 編程教程的這一部分中,我們將介紹一些 PyGTK 小部件。 小部件是 GUI 應用的基本構建塊。 多年來,幾個小部件已成為所有 OS 平臺上所有工具包中的標準。 例如,按鈕,復選框或滾動條。 PyGTK 工具箱的理念是將小部件的數量保持在最低水平。 將創建更多專門的小部件作為自定義 PyGTK 小部件。 ## `Label` `Label`小部件顯示有限數量的只讀文本。 `label.py` ```py #!/usr/bin/python # ZetCode PyGTK tutorial # # This example demonstrates the Label widget # # author: jan bodnar # website: zetcode.com # last edited: February 2009 import gtk 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""" class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_position(gtk.WIN_POS_CENTER) self.set_border_width(8) self.connect("destroy", gtk.main_quit) self.set_title("You know I'm no Good") label = gtk.Label(lyrics) self.add(label) self.show_all() PyApp() gtk.main() ``` 該代碼示例在窗口上顯示了一些歌詞。 ```py lyrics = """Meet you downstairs in the bar and heard your rolled up sleeves and your skull t-shirt ...""" ``` 這是我們顯示的文本。 ```py self.set_border_width(8) ``` `Label`周圍有一些空白。 ```py label = gtk.Label(lyrics) self.add(label) ``` `Label`小部件已創建并添加到窗口。 ![Label Widget](https://img.kancloud.cn/84/62/8462eb32a94faa62eaf39b7063ad1ac0_297x282.jpg) 圖:`Label`小部件 ## `CheckButton` `CheckButton`是具有兩種狀態的窗口小部件:打開和關閉。 n 狀態通過復選標記顯示。 它用來表示一些布爾屬性。 `checkbutton.py` ```py #!/usr/bin/python # ZetCode PyGTK tutorial # # This example demonstrates the CheckButton widget # # author: jan bodnar # website: zetcode.com # last edited: February 2009 import gtk class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_title("Check Button") self.set_position(gtk.WIN_POS_CENTER) self.set_default_size(250, 200) fixed = gtk.Fixed() button = gtk.CheckButton("Show title") button.set_active(True) button.unset_flags(gtk.CAN_FOCUS) button.connect("clicked", self.on_clicked) fixed.put(button, 50, 50) self.connect("destroy", gtk.main_quit) self.add(fixed) self.show_all() def on_clicked(self, widget): if widget.get_active(): self.set_title("Check Button") else: self.set_title("") PyApp() gtk.main() ``` 根據`CheckButton`的狀態,我們將在窗口的標題欄中顯示標題。 ```py button = gtk.CheckButton("Show title") ``` `CheckButton`小部件已創建。 ```py button.set_active(True) ``` 默認情況下標題是可見的,因此我們默認情況下選中復選按鈕。 ```py if widget.get_active(): self.set_title("Check Button") else: self.set_title("") ``` 如果選中`CheckButton`,我們將顯示標題。 否則,我們將在標題欄中放置空白文本。 ![CheckButton](https://img.kancloud.cn/fd/59/fd59f54c09dc8b38127f91506a2ee59c_258x228.jpg) 圖:`CheckButton` ## `ComboBox` `ComboBox`是一個小部件,允許用戶從選項列表中進行選擇。 `combobox.py` ```py #!/usr/bin/python # ZetCode PyGTK tutorial # # This example demonstrates the ComboBox widget # # author: jan bodnar # website: zetcode.com # last edited: February 2009 import gtk class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_title("ComboBox") self.set_default_size(250, 200) self.set_position(gtk.WIN_POS_CENTER) cb = gtk.combo_box_new_text() cb.connect("changed", self.on_changed) cb.append_text('Ubuntu') cb.append_text('Mandriva') cb.append_text('Redhat') cb.append_text('Gentoo') cb.append_text('Mint') fixed = gtk.Fixed() fixed.put(cb, 50, 30) self.label = gtk.Label("-") fixed.put(self.label, 50, 140) self.add(fixed) self.connect("destroy", gtk.main_quit) self.show_all() def on_changed(self, widget): self.label.set_label(widget.get_active_text()) PyApp() gtk.main() ``` 該示例顯示了一個組合框和一個標簽。 組合框具有六個選項的列表。 這些是 Linux 發行版的名稱。 標簽窗口小部件顯示了從組合框中選擇的選項。 ```py cb = gtk.combo_box_new_text() ``` `gtk.combo_box_new_text()`函數是一種便捷函數,可構造一個新的文本組合框。 它是只顯示字符串的`ComboBox`。 ```py cb.append_text('Ubuntu') cb.append_text('Mandriva') cb.append_text('Redhat') cb.append_text('Gentoo') cb.append_text('Mint') ``` `ComboBox`充滿了文本數據。 ```py self.label.set_label(widget.get_active_text()) ``` 在`on_changed()`方法內部,我們從組合框中獲取選定的文本并將其設置為標簽。 ![ComboBox](https://img.kancloud.cn/7e/00/7e00c101f44c5c34521a050f225cd787_258x228.jpg) 圖:`ComboBox` ## `Image` 下一個示例介紹`Image`小部件。 此小部件顯示圖片。 `image.py` ```py #!/usr/bin/python # ZetCode PyGTK tutorial # # This example demonstrates the Image widget # # author: jan bodnar # website: zetcode.com # last edited: February 2009 import gtk class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_title("Red Rock") self.set_position(gtk.WIN_POS_CENTER) self.set_border_width(2) image = gtk.Image() image.set_from_file("redrock.png") self.connect("destroy", gtk.main_quit) self.add(image) self.show_all() PyApp() gtk.main() ``` 我們在窗口中顯示紅色巖石城堡。 ```py image = gtk.Image() ``` `Image`小部件已創建。 ```py image.set_from_file("redrock.png") ``` 我們將 PNG 圖像設置為`Image`小部件。 圖片是從磁盤上的文件加載的。 ![Image](https://img.kancloud.cn/e1/4b/e14b55be241f8a49859e4929bb61fb92_460x283.jpg) 圖:圖像 在本章中,我們展示了 PyGTK 編程庫的第一組基本小部件。
                  <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>

                              哎呀哎呀视频在线观看