[Tkinter-discuss] tkinter "monitor" and root.mainloop()

Marco gaedol at gmail.com
Fri May 23 12:26:12 CEST 2008


Hi all,

and thanks for the answers: how, i avoided the sleep() approach,
because, as Cameron said i supposed that it freezed the application:
being in sleep() it stops the mainloop()...

Now,

i have used the after() approach, with some satisfactory results,
only, there is something that still bugs me: if i understand correctly
after() tells the loop to execute someething after some time (in
milliseconds). What i'd like to do is something more like every()...
In fact, i'd like the application to be redrawn every() second (so to
say), while, if i understand correctly, every time i want to redraw
the application (for example because in the meantime the log i'm
monitoring has changed) i have to call after(). In this sense i have
put an after() at the end of every possible event that the user, while
working on the interface, could do. But, if nothing happens at the GUI
level, then nothing is updated.

I'd prefer to avoid to put a "UPDATE" button on the app, but as of
now, seems like it's the only way to do it safely.

I am wrong?

thanks again,


marco

On Fri, May 23, 2008 at 1:49 AM, Cameron Laird <Cameron at phaseit.net> wrote:
> On Fri, May 23, 2008 at 09:10:48AM +1000, Peter Milliken wrote:
>                        .
>                        .
>                        .
>> in the time module, look at a function called sleep - arguments are 1 second
>> intervals from memory i.e. something like this:
>>
>> import time
>>
>> while True:
>>   <check file for changes and take appropriate action>
>>
>>   time.sleep(5)          -- delay for 5 seconds before resuming loop
>>
>>
>>
>>
>> On Thu, May 22, 2008 at 8:59 AM, Cameron Laird <Cameron at phaseit.net> wrote:
>>
>> > On Wed, May 21, 2008 at 12:49:22PM +0200, Marco wrote:
>> >                        .
>> >                        .
>> >                         .
>> > > I am quite new to tkinter programming, and i have a question.
>> > >
>> > > I am writing a "monitor": basically it reads a file on the filesystem
>> > > and reports it in a graphical way using python and tkinter.
>> > >
>> > > Now the file, over time, changes, so once called root.mainloop() i'd
>> > > need to reread the file, update the objects in memory and redraw the
>> > > tkinter main window.
>> > >
>> > > How can I achieve that? Ideas? Suggestions? Is my approach wrong?
>> >                         .
>> >                        .
>> >                        .
>> > Poll with after().  Fredrik's references, among others,
>> > explain this.  I'll be tied up for a day; if you don't
>> > work out the details on your own, I'll return to explain.
>                        .
>                        .
>                        .
> Peter, while I agree that time.sleep() can serve to
> construct a quick model of a polling operation, it
> often leads to dissatisfaction because, in contrast
> to after()-based implementations, it "freezes" the
> Tkinter windows while sleep()ing.
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>


More information about the Tkinter-discuss mailing list