Tcl/Tk 初始化脚本期间 tk_messageBox 出现问题

发布于 2024-08-18 05:41:45 字数 542 浏览 1 评论 0原文

使用以下 Tcl 脚本,条目小部件将不接受输入。它出现但没有响应。

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

如果我注释掉 tk_messageBox 行,那么条目小部件就可以正常工作。是什么原因导致此行为以及如何修复它?

我在 Windows 上使用 Tcl/Tk 8.5.2。

需要澄清的是,我的问题是消息框关闭后输入框被破坏。输入框不会接受焦点/输入,也不会显示插入符号。我已经在 Windows XP 和 Vista 上进行了测试,使用我自己编译的 Tcl/Tk 以及来自 Equi4 的 tclkit 。在每种情况下,如果初始化脚本中显示消息框,则该条目不起作用。

编辑:还有一件事。如果将代码输入交互式愿望控制台,则不会出现此“错误”。仅当代码位于文件中并且以文件名作为参数从命令行调用 Wish 时,它似乎才会失败。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

无所谓啦 2024-08-25 05:41:45

消息框是模态的,即它捕获输入焦点直到其关闭。如果您希望应用程序在打开时保持响应,则必须以不同的方式显示消息。

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.

相对绾红妆 2024-08-25 05:41:45

看起来像是一个典型的焦点问题。我已经在我的系统中进行了测试,下一个脚本似乎工作正常:

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

每当您遇到此类问题时,请认为焦点可能已经消失,您需要恢复它。检查焦点和抓取命令。

希望有帮助。

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.

双手揣兜 2024-08-25 05:41:45

我在 Windows XP 上尝试了使用 tclkit 8.5.8 的 3 行 tcl/tk 示例,它的工作方式正如人们所期望的那样。请记住,tk 8.x 使用越来越多的 Windows 本机小部件,这些小部件与仅 tk 小部件之间的交互有时可能会很棘手。

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.

南风起 2024-08-25 05:41:45

显然这是 Tk 中的一个错误。

简单的修复方法是将其

update idletasks

作为初始化脚本中的第一行代码。

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.

我乃一代侩神 2024-08-25 05:41:45

我在使用输入框时也遇到了同样的问题,但在将 focusmodel 更改为被动后得到解决。

wm focusmodel .w passive

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

wm focusmodel .w passive
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文