如何检查tk_getOpenfile是否实际打开了文件?

时间:2017-08-01 13:22:56

标签: tcl

我程序的这一部分打开一个文件,用于下载到扫描仪上以进行闪存。如果我只是关闭文件选择窗口,我会收到此错误消息 -

wrong # args: should be cksum ?-format string? -channel chan | -filename file | string
wrong # args: should be cksum ?-format string? -channel chan | -filename file | string
    while executing
"::crc::cksum -file $file2program"


set file2program [tk_getOpenFile]

## determine chsum
set filechecksum1 [::crc::cksum -file $file2program]
set filechecksum [format %X [scan $filechecksum1 %d]]
.flashutility.messagearea insert end "Checksum for binary file = $filechecksum\n"
.flashutility.messagearea see end
set filesize [file size $file2program]
.flashutility.messagearea insert end "Size of the file to transfer is $filesize bytes\n"
.flashutility.messagearea see end
update

1 个答案:

答案 0 :(得分:0)

tk_getOpenFile命令不会打开文件。它返回要打开的文件的完全限定名称。如果用户取消,则返回空字符串,这与任何平台上的任何完全限定文件名都不相同。