In PyGTK, how do you redraw parts of a window that are obscured during a long calculation?
Below is some elementary code.
- It displays a button.
- Clicking the button runs a loop.
- In the loop, if you obscure the button with a window, the obscured part will be whitish and not redraw until after the loop.
How can I make the button redraw in the loop?
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()
You could run the main iteration yourself
while gtk.events_pending():
gtk.main_iteration()
A long running task should be run in a thread outside of the main loop. See this for an example with pyGTK.
精彩评论