tags:

views:

216

answers:

4

With the following Tcl script, the entry widget will not accept input. It appears but is unresponsive.

pack [entry .a] -padx 15 -pady 15
tk_messageBox -message {test}

If I comment out the tk_messageBox line, then the entry widgets works fine. What causes this behavior and how do I fix it?

I'm using Tcl/Tk 8.5.2 on Windows.

To clarify, my problem is that the entry box is broken after the message box is dismissed. The entry box will not accept focus/input and will not display a caret. I've tested this on Windows XP and Vista, using Tcl/Tk I compiled myself, and with the tclkit from Equi4. In each case, the entry doesn't work if a message box is display in the initialization script.

Edit: One more thing. This "bug" is not present if the code is typed into an interactive wish console. It only seems to fail when the code is in a file and wish is invoked from the command line with the file name as an argument.

A: 

The message box is modal, i.e. it captures input focus until it's closed. You'd have to show your message in a different way if you want your app to remain responsive while it's open.

Tung Nguyen
No, the entry widget is broken even after the message box is dismissed.
Imbue
Works fine for me, using 8.5.1 on WinXP
Jeff Godfrey
Oh, in that case, I don't know what's up either. Under Linux with the same version of Tcl/Tk, it's modal, and the entry box works fine once it's dismissed.
Tung Nguyen
Are you sure it's not just a focus-related problem? Does clicking in the entry after dismissing the message box make it work?
Jeff Godfrey
I cannot get it to work after the message box is dismissed. Clicking doesn't work. Tabbing doesn't work. Right clicking has no response. When the mouse cursor hovers over the entry, the cursor turns to the caret symbol, but I cannot get a caret to appear in the entry box no matter what. I've been able to reproduce the error on a couple computers, so I'm quite surprised no one else can.
Imbue
A: 

Hi Jan,

Seems like a typical focus problem. I've tested in my system and the next script seems to work fine:

pack [entry .a] -padx 15 -pady 15
tk_messageBox -message {test} focus
focus -force .a

Whenever you have this type of problems think that the focus may be gone and you need to recover it. Check both focus and grab commands.

Hope it helps.

Carlos Tasada
A: 

I tried the 3 line tcl/tk example with tclkit 8.5.8 on windows xp and it worked as one would expect it to. Remember that tk 8.x uses more and more Windows native widgets, and interactions between these and tk only widgets can at times be thorny.

lvirden
A: 

I found an answer to my question on comp.lang.tcl here.

The simple fix is to put

update idletasks

as the first line of code in the initialization script.

Imbue