简体   繁体   English

gtk TextView小部件在功能运行期间不会更新

[英]gtk TextView widget doesn't update during function

I'm new to GUI programming with python and gtk, so this is a bit of a beginners question. 我是使用python和gtk进行GUI编程的新手,所以这是一个初学者的问题。 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. 我有一个函数,当按下一个按钮来执行各种任务时会调用该函数,还有一个TextView小部件,我在完成每个任务后将其写入。 The problem is that the TextView widget doesn't update until the entire function has finished. 问题在于TextView小部件在整个功能完成之前不会更新。 I need it to update after each task. 我需要在每个任务之后进行更新。

After each update to the TextView call 每次更新TextView调用后

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()

From the PyGTK FAQ: How can I force updates to the application windows during a long callback or other internal operation? 从PyGTK常见问题解答: 如何在长时间的回调或其他内部操作期间强制对应用程序窗口进行更新?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM