下面是一些基本代码。
如何在循环中重绘按钮?
import gtk
class MyClass:
def __init__(self):
window = gtk.Window()
window.connect("destroy", gtk.main_quit)
window.set_size_request(200, 50)
table = gtk.Table()
# Add a button to the table.
button = gtk.Button("Button")
col = 0
row = 0
table.attach(button, col, col + 1, row, row + 1)
button.connect("clicked", self.clicked_event_handler)
window.add(table)
window.show_all()
def clicked_event_handler(self, button):
for i in range(10**8):
pass
if __name__ == "__main__":
MyClass()
gtk.main()
答案 0 :(得分:1)
您可以自己运行主要迭代
while gtk.events_pending():
gtk.main_iteration()
答案 1 :(得分:0)
长时间运行的任务应该在主循环之外的线程中运行。有关pyGTK的示例,请参阅this。