错误位图 0 未定义

Error bitmap 0 not defined

我的代码是检查某些文件中的值 returned,我将回调附加到一个按钮,按下该按钮时应根据 return 值向用户显示一个对话框。 但是当代码被执行时,它 return 是一个错误消息位图“0”未定义。

代码:

#!/usr/local/bin/wish

##set command "lmstat -a -c /tools/license/dat/cadence_orbit_3x.dat -f Liberate_MX_Client | grep issued | awk {{print }}"

set result [exec lmstat -a -c /tools/license/dat/cadence_orbit_3x.dat -f Liberate_LX_Server | grep issued | awk {{print }}]
puts $result
if {$result == 0} {
button .hello -text "License Check" -command {checkLic} -bg green 
} else  {
button .hello -text "License Check" -command {checkLic} -bg red 

}
proc checkLic {} {
set val [exec lmstat -a -c /tools/license/dat/cadence_orbit_3x.dat -f Liberate_MX_Client | grep issued | awk {{print }}]
puts $val
if {$val == 0} {
after 5000 {destroy .dialog2}
     tk_dialog .dialog2 "Liberate licenses available" info 0 OK

} else  {

after 5000 {destroy .dialog2}
     tk_dialog .dialog2 "No licenses available" info 0 OK
}
}

pack .hello -padx 20 -pady 10

manual page for tk_dialog 说:

tk_dialog window title text bitmap default string string ...

This procedure is part of the Tk script library. It is largely deprecated by the tk_messageBox. Its arguments describe a dialog box:

window: Name of top-level window to use for dialog. Any existing window by this name is destroyed.

title: Text to appear in the window manager's title bar for the dialog.

text: Message to appear in the top portion of the dialog box.

bitmap: If non-empty, specifies a bitmap (in a form suitable for Tk_GetBitmap) to display in the top portion of the dialog, to the left of the text. If this is an empty string then no bitmap is displayed in the dialog.

default: If this is an integer greater than or equal to zero, then it gives the index of the button that is to be the default button for the dialog (0 for the leftmost button, and so on). If less than zero or an empty string then there will not be any default button.

string: There will be one button for each of these arguments. Each string specifies text to display in a button, in order from left to right.

我猜你错过了要在对话框中使用的 titletext,使你的价值重新打算提供作为 default 落入 bitmap 槽,这混淆了代码。添加一个额外的参数,可能像这样(为了便于阅读而分为两行):

tk_dialog .dialog2 "Liberate licenses available" \
        "There are some licenses available; great!" info 0 OK

一般建议

你的逻辑看起来有点狡猾。关于没有执照的投诉应该在 else 条款中吗?

此外,我将实际的 exec 行放在它自己的程序中 只是 这样所有使用它的地方都可以准确地您可以确定的相同版本是正确的。它减少了可能出错的方式的数量,以便您可以更轻松地查找任何错误。