Double infinite loop

Fredrik Lundh fredrik at effbot.org
Thu Nov 16 03:06:22 EST 2000


Arne Meyer Hansen wrote:
> I'm writing a script that gathers information from newspapers and updates
> it regularly with the newest headlines. The principle is simple:
>
> while 1:
>   updateHeadlines()
>   time.sleep(180)
>
> The trouble is, I want to display the results in a GUI, which requires
> entering Tk's mainloop(). How can I combine the two infinte loops?
>
> My best suggestions so far are:
>
> - Binding some sort of timer-event that calls the updateHeadlines-function
> at regular intervals (which seems reasonable, except that I'm not sure if
> it is possible in Python. That is, I haven't found any documentation about
> it).

http://www.pythonware.com/library/tkinter/introduction/basic-widget-methods.htm
=> Alarm handlers and other non-event callbacks => alarm (and friends)

here's an example:

    class myapp:

        def __init__(self, root):
            self.root = root # root window
            # ...create widgets...
            self.poll() # start polling

        def poll(self):
            updateHeadlines()
            self.root.update_idletasks() # make sure they're displayed
            self.root.after(180*1000, self.poll)

</F>





More information about the Python-list mailing list