pygtk关于设置按钮敏感属性的奇怪问题
在我的方法之一上,我有以下代码:
def fun():
self.button1.set_sensitive(False)
self.get_time()
但是,self.button1 仅在 get_time() 返回后变得不敏感!!,使用 time.sleep(n) 替换 get_time() 可以获得相同的结果 有什么线索吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为对小部件的编程更改适用于事件循环 (
gtk.main()
) 的下一圈,这可能是在完成fun
函数之后。这对你来说有问题吗?多少时间self.get_time()
需要?如果这需要一定的时间,您可以在此之前更新小部件:
I think programmic changes to widgets applies in the next lap of event loop (
gtk.main()
), that is probably after finishingfun
function. Does that make a problem for you? How much timeself.get_time()
takes? If that takes a sensible time, you can update widgets before that:
呃,您确定要这样做吗?
所有 GUI 编程事件都是通过消息传递完成的,因此您实际上不应该阻塞主线程足够长的时间,否则您将需要一些像这样的解决方法。如果您这样做,您很快就会遇到其他问题,例如窗口管理器杀死您的窗口,因为在您进行迭代时它没有响应 ping 或重入问题。如果您有一些复杂的任务,例如刻录 CD 或任何需要很长时间的任务,请将实际刻录放入其自己的可执行文件中,并通过 glib.spawn_async (或类似的)调用它。使用 gobject.child_watch_add 请求获得有关终止的通知。
Uhh are you sure you want to do that?
All GUI programming events are done by message passing and so you really shouldn't block the main thread for long enough you'd ever need some workaround like this. And if you do that, you'll soon have other problems like the window manager killing your window because it's not responding to ping or reentrance problems when you do the iteration. If you have some complicated task like burning a CD or whatever that takes that long, put the actual burning into its own executable and call it by glib.spawn_async (or similar). Use gobject.child_watch_add to ask to be notified about termination.