<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Tcl/Tk 中的菜單和工具欄 > 原文: [http://zetcode.com/gui/tcltktutorial/menustoolbars/](http://zetcode.com/gui/tcltktutorial/menustoolbars/) 在 Tcl/Tk 教程的這一部分中,我們將使用菜單和工具欄。 菜單欄是 GUI 應用中最可見的部分之一。 它是位于各個菜單中的一組命令。 在控制臺應用中,我們必須記住許多奧術命令,在這里,我們將大多數命令分組為邏輯部分。 有公認的標準可以進一步減少學習新應用的時間。 菜單將我們可以在應用中使用的命令分組。 使用工具欄可以快速訪問最常用的命令。 ## 簡單菜單 第一個示例將顯示一個簡單的菜單。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this code example, we create # a simple menu. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com menu .mbar . configure -menu .mbar menu .mbar.fl -tearoff 0 .mbar add cascade -menu .mbar.fl -label File \ -underline 0 .mbar.fl add command -label Exit -command { exit } wm title . "Simple menu" wm geometry . 250x150+300+300 ``` 我們的示例將顯示一個文件菜單,其中包含一項。 通過選擇退出菜單項,我們關閉應用。 ```tcl menu .mbar . configure -menu .mbar ``` 我們創建一個菜單欄。 菜單欄是菜單的特例。 ```tcl menu .mbar.fl -tearoff 0 ``` 創建文件菜單。 `-tearoff`選項指定無法從菜單欄中刪除菜單。 ```tcl .mbar add cascade -menu .mbar.fl -label File \ -underline 0 ``` 我們將文件菜單添加到菜單欄。 `-underline`選項在標簽的第一個字符下劃線。 現在可以使用 `Alt + F` 快捷方式下拉菜單。 ```tcl .mbar.fl add command -label Exit -command { exit } ``` `Exit`命令被添加到文件菜單。 這將創建一個菜單項。 選擇菜單項后,應用終止。 ![Simple menu](https://img.kancloud.cn/59/3d/593d67854679d2487ec29ea549d33a86_252x212.jpg) 圖:簡單菜單 ## 子菜單 子菜單是插入另一個菜單對象的菜單。 下一個示例對此進行了演示。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this code example, we create # a submenu. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com menu .mbar . configure -menu .mbar menu .mbar.fm -tearoff 0 .mbar add cascade -menu .mbar.fm -label File \ -underline 0 menu .mbar.fm.sb .mbar.fm.sb add command -label "News feed" .mbar.fm.sb add command -label Bookmarks .mbar.fm.sb add command -label Mail .mbar.fm add cascade -label Import -menu \ .mbar.fm.sb -underline 0 .mbar.fm add separator .mbar.fm add command -label Exit -underline 0 \ -command {exit} wm title . submenu wm geometry . 250x150+300+300 ``` 在示例中,文件菜單的子菜單中有三個選項。 我們創建一個分隔符和鍵盤快捷鍵。 ```tcl menu .mbar.fm.sb .mbar.fm.sb add command -label "News feed" .mbar.fm.sb add command -label Bookmarks .mbar.fm.sb add command -label Mail ``` 我們有一個包含三個命令的子菜單。 子菜單是常規菜單。 注意小部件路徑名的層次結構。 ```tcl .mbar.fm add cascade -label Import -menu \ .mbar.fm.sb -underline 0 ``` 通過將菜單添加到“文件”菜單而不是菜單欄,我們創建了一個子菜單。 下劃線參數創建鍵盤快捷鍵。 我們提供了角色位置,應在下面加下劃線。 在我們的情況下,這是第一個。 位置從零開始。 當我們單擊“文件”菜單時,將顯示一個彈出窗口。 導入菜單下劃線一個字符。 我們可以使用鼠標指針或 `Alt + I` 快捷方式選擇它。 ```tcl .mbar.fm add separator ``` 分隔符是一條水平線,可以在視覺上分隔菜單命令。 這樣,我們可以將項目分組到一些合理的位置。 ![Submenu](https://img.kancloud.cn/ea/ac/eaac3e43776c34cd786dee758d8e570e_252x212.jpg) 圖:子菜單 ## 彈出菜單 在下一個示例中,我們創建一個彈出菜單。 彈出菜單是上下文窗口小部件,可以在窗口的客戶區域中的任何位置顯示。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this code example, we create # a popup menu. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com menu .m -tearoff 0 .m add command -label Beep .m add command -label Exit -command {exit} bind . "<Button-3>" "showMenu %X %Y" wm title . popupmenu wm geometry . 250x150+300+300 proc showMenu {x y} { tk_popup .m $x $y } ``` 在我們的示例中,我們使用兩個命令創建一個彈出菜單。 ```tcl menu .m -tearoff 0 .m add command -label Beep .m add command -label Exit -command {exit} ``` 上下文菜單是常規的`menu`小部件。 `tearoff`函數已關閉。 ```tcl bind . "<Button-3>" "showMenu %X %Y" ``` 我們將`<Button-3>`事件綁定到`showMenu`過程。 當我們右鍵單擊窗口的客戶區域時,將生成事件。 我們將兩個參數傳遞給該過程。 這些是鼠標單擊的 x 和 y 坐標。 ```tcl proc showMenu {x y} { tk_popup .m $x $y } ``` `showMenu`過程顯示上下文菜單。 彈出菜單顯示在鼠標單擊的 x 和 y 坐標處。 要顯示彈出菜單,我們使用`tk_popup`命令。 ![Popup menu`](https://img.kancloud.cn/9e/82/9e82b527e320b48fe3d9d70c3b4723e8_252x182.jpg) 圖:彈出菜單 ## 工具欄 菜單將我們可以在應用中使用的命令分組。 使用工具欄可以快速訪問最常用的命令。 Tk 中沒有工具欄小部件。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this code example, we create # a toolbar. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com package require Img menu .mbar . configure -menu .mbar menu .mbar.fl -tearoff 0 .mbar add cascade -menu .mbar.fl -label File \ -underline 0 frame .toolbar -bd 1 -relief raised image create photo img -file "exit.png" button .toolbar.exitButton -image img -relief flat -command {exit} pack .toolbar.exitButton -side left -padx 2 -pady 2 pack .toolbar -fill x wm title . toolbar wm geometry . 250x150+300+300 ``` 我們的工具欄將是一個框架,在該框架上將放置一個按鈕。 ```tcl frame .toolbar -bd 1 -relief raised ``` 工具欄已創建。 它是`frame`。 我們創建了一個凸起的邊框,以便工具欄的邊界可見。 ```tcl image create photo img -file "exit.png" button .toolbar.exitButton -image img -relief flat -command {exit} ``` 創建帶有圖像的退出按鈕。 ```tcl pack .toolbar.exitButton -side left -padx 2 -pady 2 ``` 工具欄是框架,框架是容器小部件。 我們將按鈕包裝在左側。 我們添加一些填充。 ```tcl pack .toolbar -fill x ``` 工具欄打包在根窗口中; 它是水平拉伸的。 ![Toolbar](https://img.kancloud.cn/f7/99/f799353d12832515182083c296d21565_252x212.jpg) 圖:工具欄 在 Tcl/Tk 教程的這一部分中,我們展示了如何創建帶有菜單和菜單項以及工具欄的菜單欄。
                  <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>

                              哎呀哎呀视频在线观看