參閱:Tcl/Tk 教程
set PATH 新增?D:\Git\mingw64\bin
where tclsh
D:\Git\mingw64\bin\tclsh.exe
where wish
D:\Git\mingw64\bin\wish.exe
編寫 test_tk.tcl? 如下
#!/usr/bin/tclsh
# test 文件對話框
package require Tk# 彈出文件選擇對話框,限制選擇.txt文件
set filePath [tk_getOpenFile -title "選擇文件" \-filetypes {{"文本文件" {.txt}} {"所有文件" {*.*}}}]# 檢查用戶是否選擇了文件
if {$filePath != ""} {exec notepad.exe $filePath
} else {tk_messageBox -title "Error" -message "沒有選擇文件!" -icon error
}
運行? tclsh test_tk.tcl?
或者 wish test_tk.tcl?
編寫 open_video.tcl? 如下
#!/usr/bin/tclsh
# test 文件對話框
package require Tk# 彈出文件選擇對話框,限制選擇.avi文件
set dir1 "D:/VIDEO"
set filePath [tk_getOpenFile -title "選擇文件" \-filetypes {{"AVI文件" {.avi}} {"All Files" {*.*}}} \-initialdir $dir1 ]# 檢查用戶是否選擇了文件
if {$filePath != ""} {exec "C:/Program Files/Windows Media Player/wmplayer.exe" $filePath
} else {tk_messageBox -title "Error" -message "沒有選擇文件!" -icon error
}
運行 wish open_video.tcl?
?注意:腳本編碼需要轉為ANSI/GBK,如果是UTF-8,中文顯示會亂碼。