Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why destroy error happen ?

Status
Not open for further replies.

dotaliu

Technical User
Mar 25, 2008
15
CN
ex1:
#!/usr/bin/wish
toplevel .dialog
button .dialog.ok -text "OK" -command {
destroy .dialog
}
pack .dialog.ok

ex2:
#!/usr/bin/wish
toplevel .dialog
button .dialog.ok -text "OK"
bind .dialog.ok <Enter> {
destroy .dialog
}
bind .dialog.ok <Button-1> {
destory .dialog
}

ex2 report "Error: invalid command name .dialog.ok" while ex1 is ok. why is happen? and how to write this script ?
 
I think the problem is that there are a whole load of bindings already attached to a button by definition, so when you destroy the button in ex2, with the button1 binding, the built in binding tries to execute bat cannot find the button. I think your code should read:

#!/usr/bin/wish
toplevel .dialog
button .dialog.ok -text "OK"
pack .dialog.ok
bind .dialog.ok <Return> {
destroy .dialog
}
bind .dialog.ok <ButtonPress-1> {
destroy .dialog
}

But it still won't work! You will need to make your own "button" with, for example, a label widget instead:

#!/usr/bin/wish
toplevel .dialog
label .dialog.ok -text "OK" -borderwidth 2 -relief raised -width 4
pack .dialog.ok
focus .dialog.ok
bind .dialog.ok <Return> {
destroy .dialog
}
bind .dialog.ok <ButtonPress-1> {
destroy .dialog
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top