如何在程序运行时显示列表框或文本
这是我的编码。我面临一个问题,即它仍在运行时没有显示“.display_message”。仅在 proc torun {} 完成其任务后我才收到消息。顺便说一句,2000年后实际上是我的程序在运行。这是一个很长的代码,我觉得它不适用,所以我删除了它以简化它。请在这方面指导我。谢谢。
proc torun {} {
set total [.display_pc2 size]
.display_message insert end "test"
for {set x 0} {$x < $total} {incr x} {
set machine [.display_pc2 get $x]
.display_message insert end "Copy to $machine now. Please wait..."
.display_message see end
after 2000
.display_message insert end "Copy to $machine done"
.display_message see end
after 2000
}
}
This is my coding. I am facing a problem where it didn't display the ".display_message" while it is still running. I receive the message only after the proc torun {} completed its task. Btw, after 2000 is actually my program running. It is a very long code where I feel it is not applicable so I removed it to simplified it. Please guide me in this. Thanks.
proc torun {} {
set total [.display_pc2 size]
.display_message insert end "test"
for {set x 0} {$x < $total} {incr x} {
set machine [.display_pc2 get $x]
.display_message insert end "Copy to $machine now. Please wait..."
.display_message see end
after 2000
.display_message insert end "Copy to $machine done"
.display_message see end
after 2000
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该完全改变编写此代码的方式并使用空闲回调。
这个想法是,您创建一个要执行的“任务”列表(可能是目标计算机的列表),将其保存在某处,然后一次处理一项,使用空闲回调重新安排执行。
草图如下:
You should completely change the way you write this code and use idle callbacks.
The idea is that you create a list of "tasks" to do (probably that would be a list of targets computers), save it somewhere and then process it one item at a time, rescheduling the execution using idle callback.
A sketch follows:
我从来没有做过 tk (如果你正在做的是 gui),但当使用
puts
强制显示消息时,也许你需要一些与flush
等效的东西。因为我无法猜测
.display_message
过程中做了什么。编辑:
刚刚有了一个想法:您可以使用
after
命令来伪造多线程您的应用程序。after 0 [list .display_message insert end "立即复制到 $machine。请稍候..."; .display_message see end]
它将作为事件处理程序独立于当前进程运行。也许这可以解决您的冲水问题。 (需要 eventloop 或 update 命令)
I've never done tk (if it's gui what you're doing), but maybe you need some equivalent to
flush
when usingputs
to force-display a message.Since I can't guess what's done inside the
.display_message
proc.Edit:
Just got an idea: You can use the
after
command to fake-multithread your app.after 0 [list .display_message insert end "Copy to $machine now. Please wait..."; .display_message see end]
Which will run independently from your current proc as event handler. Maybe that fixes your flush problem. (Requires the eventloop or
update
command)