在 Win 10 上,Tcl/Tk 脚本2个示例

参阅: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,中文显示会乱码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值