gtk TextView小部件在函数中不会更新 [英] gtk TextView widget doesn't update during function

查看:206
本文介绍了gtk TextView小部件在函数中不会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用python和gtk进行GUI编程的新手,所以这是一个初学者的问题。
我有一个函数,当按下按钮执行各种任务时会调用它,并且每个任务完成后我都会写入一个TextView小部件。问题是TextView小部件在整个函数完成之前不会更新。我需要它在每个任务完成后更新。

I'm new to GUI programming with python and gtk, so this is a bit of a beginners question. I have a function that is called when a button is pressed which does various tasks, and a TextView widget which I write to after each task is completed. The problem is that the TextView widget doesn't update until the entire function has finished. I need it to update after each task.

推荐答案

在每次更新TextView调用之后

After each update to the TextView call

while gtk.events_pending():
  gtk.main_iteration()

您可以通过自定义函数进行更新:

You can do your update through a custom function:

def my_insert(self, widget, report, text):

  report.insert_at_cursor(text)
  while gtk.events_pending():
    gtk.main_iteration()

从PyGTK FAQ:
如何在长回调或其他内部操作期间强制更新应用程序窗口?

From the PyGTK FAQ: How can I force updates to the application windows during a long callback or other internal operation?

这篇关于gtk TextView小部件在函数中不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆