[Tkinter-discuss] Stopping a for loop with a sleep() funciton in it

Guilherme Polo ggpolo at gmail.com
Fri Jul 11 00:52:50 CEST 2008


On Thu, Jul 10, 2008 at 7:31 PM, Alexnb <alexnbryan at gmail.com> wrote:
>
>
>
> Guilherme Polo wrote:
>>
>> On Thu, Jul 10, 2008 at 5:57 PM, Alexnb <alexnbryan at gmail.com> wrote:
>>>
>>> Okay, so I have a for loop with a sleep command. I want the loop to
>>> continue
>>> until it is told to stop. I want to tell it to stop when a list goes from
>>> empty to having something. The problem is that when that loop starts, the
>>> program pretty much stops with it.
>>
>> You need to remove the use of sleep and use "after" instead. You keep
>> scheduling your task till the condition is not met anymore, then you
>> stop scheduling it with "after".
>>
>>> To make things harder, I really want that
>>> to be it's own class, so I have to pass it the list that triggers the
>>> stopping, but I can only pass it the list once. So I don't think it is
>>> possible.
>>
>> It is, just pass some other object along which can call the method
>> "after".
>>
>>> But if this made sense to anyone, and you have a suggestion I
>>> would love it. Heres the full code: (but at the bottom, the Open function
>>> is
>>> really the only thing that matters)
>>>
>>
>> If you want help based on code, you have to post a short-enough code
>> that demonstrates the problem.
>>
>>> from Tkinter import *
>>> import time
>>>
>>> class BusyBar(Frame):
>>> ...
>>
>>
>>
>> --
>> -- Guilherme H. Polo Goncalves
>> _______________________________________________
>> Tkinter-discuss mailing list
>> Tkinter-discuss at python.org
>> http://mail.python.org/mailman/listinfo/tkinter-discuss
>>
>>
>
> Okay, so I modified the bottom code to this:
>
> def Open(root):
>
>    bb = BusyBar(root, text='Grabbing Definitions')
>    bb.pack(side=LEFT, expand=NO)
>
>
>    def sleeper():
>        root.update

What if you change this to root.update() ?

>        root.after(1, sleeper)

after works with milliseconds, not seconds, be aware.

>    bb.on()
>    root.update_idletasks()
>
>    sleeper()
>
>    #for i in range(0, 100):
>        #time.sleep(0.1)
>        #root.update()
>    bb.of()
>
> but it doesn't repeat. What am I missing?
>


-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list