If statement 如何检查字符串是否为空

If statement 如何检查字符串是否为空,if-statement,tcl,tk,If Statement,Tcl,Tk,我需要检查字符串(输入框上的用户输入)是否为空,并在按下“播放”按钮后根据该条件执行一些操作。 这是我的剧本: entry .eInput -width 50 -relief sunken -justify center -textvariable Input button .bAction -text "Play" -width 30 -height 5 -activebackground green -font "-12" bind .bAction <1> { if {

我需要检查字符串(输入框上的用户输入)是否为空,并在按下“播放”按钮后根据该条件执行一些操作。 这是我的剧本:

entry .eInput -width 50 -relief sunken -justify center -textvariable Input
button .bAction  -text "Play" -width 30 -height 5 -activebackground green -font "-12" 

bind .bAction <1> {
 if {$Input ne ""}
  { puts "string is not empty"}
 else { puts "string is empty"}
                  }

有没有关于如何修复它的想法?

问题是,如果

if {$Input ne ""}
无效。在Tcl中,命令以换行符结尾

尝试使用

if {$Input ne ""} then {
    puts "string is not empty"
} else {
    puts "string is empty"
}

有些人喜欢在
if
s和
while
s中使用反斜杠换行符。我讨厌这样,但有些人坚持这样做。请注意,
then
关键字参数是可选的,通常会被忽略。
else
关键字也是可选的,但通常是为了清晰起见而添加的。
if {$Input ne ""} then {
    puts "string is not empty"
} else {
    puts "string is empty"
}