gtk TextView小部件在函数中不会更新 [英] gtk TextView widget doesn't update during function
问题描述
我是使用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屋!