开发者

Problem with tk_messageBox during Tcl/Tk initialization script

开发者 https://www.devze.com 2022-12-17 01:47 出处:网络
With the following Tcl script, the entry widget will not accept input. It appears but is unresponsive.

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. I开发者_如何学编程n 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.


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.


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.


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.


Apparently it is a bug in Tk.

The simple fix is to put

update idletasks

as the first line of code in the initialization script.


I was also facing same issue while using entry box, but got resolved after changing focusmodel to passive.

wm focusmodel .w passive
0

精彩评论

暂无评论...
验证码 换一张
取 消