开发者

In PyGTK, how do you redraw parts of a window that are obscured during a long calculation?

开发者 https://www.devze.com 2023-03-04 22:09 出处:网络
Below is some elementary code. It displays a button. Clicking the button runs a loop. In the loop, if you obscure

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号