<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Tcl/Tk 中的對話框 > 原文: [http://zetcode.com/gui/tcltktutorial/dialogs/](http://zetcode.com/gui/tcltktutorial/dialogs/) 在 Tcl/Tk 教程的這一部分中,我們將使用對話框。 對話框窗口或對話框是大多數現代 GUI 應用必不可少的部分。 對話被定義為兩個或更多人之間的對話。 在計算機應用中,對話框是一個窗口,用于與應用“對話”。 對話框用于輸入數據,修改數據,更改應用設置等。對話框是用戶與計算機程序之間進行通信的重要手段。 ## `MessageDialog` 消息框是方便的對話框,可向應用的用戶提供消息。 該消息由文本和圖像數據組成。 用`tk_messageBox`命令創建 Tk 中的消息框。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this program, we show various # message boxes. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com frame .fr pack .fr ttk::button .fr.erButton -text Error -command onError grid .fr.erButton ttk::button .fr.wButton -text Warning -command onWarn grid .fr.wButton -row 1 -column 0 ttk::button .fr.queButton -text Question -command onQuest grid .fr.queButton -row 0 -column 1 -sticky we -columnspan 6 ttk::button .fr.infButton -text Information -command onInfo grid .fr.infButton -row 1 -column 1 proc onError {} { tk_messageBox -type ok -icon error -title Error \ -message "Could not open file" } proc onWarn {} { tk_messageBox -type ok -icon warning -title Warning \ -message "Deprecated function call" } proc onQuest {} { tk_messageBox -type ok -icon question -title Question \ -message "Are you sure to quit?" } proc onInfo {} { tk_messageBox -type ok -icon info -title Information \ -message "Download completed" } wm title . "message boxes" wm geometry . 300x150+300+300 ``` 我們使用網格管理器來設置四個按鈕的網格。 每個按鈕顯示一個不同的消息框。 ```tcl ttk::button .fr.erButton -text Error -command onError grid .fr.erButton ``` 我們創建一個錯誤按鈕,它調用`onError`過程。 在方法內部,我們顯示錯誤消息對話框。 該按鈕將放置在網格的第一個單元格中。 `ttk`名稱空間內的小部件為主題。 就功能而言,`button`和`ttk::button`是相同的按鈕。 不同之處在于我們可以將主題應用于后者。 ```tcl proc onError {} { tk_messageBox -type ok -icon error -title Error \ -message "Could not open file" } ``` 如果按下錯誤按鈕,則會顯示錯誤對話框。 我們使用`tk_messageBox`命令創建消息框。 `-type`選項指定對話框中顯示哪些按鈕。 在我們的情況下,這是一個確定按鈕。 `-icon`指定要顯示的圖標的類型。 `-title`提供對話框的標題,`-message`提供消息。 ![Warning message dialog](https://img.kancloud.cn/19/be/19be2243843d97b4ed617ecdd5124cc9_221x122.jpg) 圖:警告消息對話框 ## 顏色選擇器 顏色選擇器是用于選擇顏色的對話框。 我們使用`tk_chooseColor`命令顯示對話框。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this script, we use tk_chooseColor # dialog to change the colour of the text. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com label .l -text ZetCode place .l -x 20 -y 90 button .b -text "Choose a color..." \ -command "onSelect .l" place .b -x 20 -y 30 wm title . "color dialog" wm geometry . 350x200+300+300 proc onSelect {widget} { set col \ [tk_chooseColor -title "Choose a color" -parent .] $widget configure -foreground $col } ``` 我們有一個按鈕和一個標簽。 單擊按鈕,我們顯示一個顏色選擇器對話框。 我們將通過從對話框中選擇一種顏色來更改標簽文本的顏色。 ```tcl label .l -text ZetCode place .l -x 20 -y 90 ``` 我們創建一個`label`小部件并將其放在窗口中。 ```tcl button .b -text "Choose a color..." \ -command "onSelect .l" place .b -x 20 -y 30 ``` 我們創建一個`button`小部件并將其放在窗口中。 我們將標簽的窗口小部件路徑傳遞給`onSelect`過程,該過程顯示對話框并更改標簽的顏色。 ```tcl proc onSelect {widget} { set col \ [tk_chooseColor -title "Choose a color" -parent .] $widget configure -foreground $col } ``` 在`onSelect`程序內部,我們顯示對話框并更改標簽顏色。 首先,我們顯示對話框并將所選的顏色值存儲在`col`變量中。 稍后,我們使用`configure`命令更改標簽的前景。 該命令在小部件的路徑名上執行。 標簽的路徑名已傳遞給過程。 ![Color chooser](https://img.kancloud.cn/cb/9a/cb9a750d63c13ae0a38d86b11577f606_418x227.jpg) 圖:顏色選擇器 ## 文件對話框 `tk_getOpenFile`對話框允許用戶從文件系統中選擇文件。 ```tcl #!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this program, we use the # tk_getOpenFile dialog to select a file from # a filesystem. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com set types { {"All Source Files" {.tcl .tk } } {"Image Files" {.gif .png .jpg} } {"All files" *} } proc onSelect { label } { global types set file [tk_getOpenFile -filetypes $types -parent .] $label configure -text $file } label .l -text "..." place .l -x 20 -y 90 button .b -text "Select a file" \ -command "onSelect .l" place .b -x 20 -y 30 wm title . "openfile" wm geometry . 350x200+300+300 ``` 在我們的代碼示例中,我們使用`tk_getOpenFile`對話框選擇一個文件,并在`label`小部件中顯示其名稱。 ```tcl set types { {"All Source Files" {.tcl .tk } } {"Image Files" {.gif .png .jpg} } {"All files" *} } ``` 這些是文件過濾器。 這些過濾器可用于僅顯示對話框中的特定文件。 ```tcl proc onSelect { label } { global types set file [tk_getOpenFile -filetypes $types -parent .] $label configure -text $file } ``` 我們使用`tk_getOpenFile`命令顯示對話框。 我們使用`-filetypes`選項應用文件過濾器。 所選文件名存儲在`file`變量中。 `configure`命令用于更改標簽的文本。 ![tk_getOpenFile](https://img.kancloud.cn/38/e2/38e2eac13557f8cba7de75605c7cf7ac_427x278.jpg) 圖:`tk_getOpenFile` 在 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>

                              哎呀哎呀视频在线观看