Version 13 of grab

Updated 2003-09-20 06:33:11

grab ?-global? window grab current ?window? grab release window grab set ?-global? window grab status window

Programmers should be cautious when issuing grabs. This basically takes control from the user, leaving them at the mercy of a program that might not be operating as expected...

Not only that, but if the user needs for instance to copy and pass data from another window, or needs to handle some emergency, and the app has issued a grab, the app is not going to be looked upon kindly.

Best don't do that. Joe English wrote in the comp.lang.tcl newsgroup:

My two rules for [grab -global]:

(1) don't use it unless I'm absolutely sure I know what I'm doing, and

(2) if I think I need it this is a sure sign that I don't know what I'm doing :-)

Bryan Oakley's advice for working with global grabs:

While in development, always put in a failsafe. For example, I'll typically add code such as "after 60000 exit" to quit the application in one minute. That way, if my code has a bug and the grab doesn't get released, my system is only frozen for a minute. Otherwise, depending on circumstances, the system might require a reboot.

Later, Bryan writes in comp.lang.tcl:

I use a global grab in my combobox code with great effect. I've not once heard of a complaint related to the grab (though maybe those poor souls are still locked out of their machine and can't send me a message..).

If memory serves, the main reason was to make it so the combobox dropdown goes away with any mouse click anywhere outside the combobox. A global grab was just the ticket.

But yes, global grabs should be avoided if at all possible. Even then, they should be avoided unless absolutely, positively unavoidable. And yet, even then you need to think twice before doing it :-)

The few times I've played with global grabs I've always (except for the first time...) set a timer that releases the grab after a minute or so, to make sure I don't hose myself. The first time, I didn't do this and the experience wasn't very pleasant.

Category Command in the Tk package - Tk syntax help - Arts and Crafts of Tcl-Tk Programming