2
我需要检查一个字符串(输入框上的用户输入)是否为空,并且在我按下“播放”按钮时根据该条件执行一些操作。 这是我的脚本:如何检查字符串是否为空
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"}
}
但是,当我按下“播放”按钮,这是错误:
wrong # args: no script following "$Input ne """ argument
wrong # args: no script following "$Input ne """ argument
while executing
"if {$Input ne ""}"
(command bound to event)
就如何解决它的任何想法?
有些人喜欢在他们的'if's和'while's使用反斜杠换行。我讨厌那个,但有些人坚持。 –
请注意,'then'关键字参数是可选的,通常省略。 –
'else'关键字也是可选的,但为了清楚起见,通常添加。 –