Jimmy
Jimmy

Reputation: 145

TCL: When click the "x" button show: invoked break outside of a loop

I want to use bgerror to show the error information, an example:

entry .e -textvariable name
button .b -text check -command [list CheckName]
grid .e
grid .b

proc CheckName {} {
   global name
   if {$name>0} {
       ....
   } else {
       bgerror "Please Input the name!"
   }
}

For the error window, if i click the "OK" button, that's ok, but if i click the "x" button, there will show another message "invoked break outside of a loop", how to solve this problem? thanks!

Upvotes: 0

Views: 277

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137587

The bgerror callback is not just a standard procedure, as it interacts with the event loop specially. In particular, if it gives a break condition, it triggers the draining of any queued errors. It also reads from the errorInfo global variable to get the current stack trace.

The easiest way to use it in approximately the way you want is to inject the error into the event loop as the result of processing an event. Here is a simple way to do this:

after idle [list error "this is an error message"] 

Upvotes: 3

Related Questions