On Fri, May 23, 2008 at 02:52:44PM +0000, Cameron Laird wrote:
> .
> .
> .
> > 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?
> .
> .
> .
> Yes and no.
>
> every() is a common need among Tkinter() programmers,
> for all the reasons you describe. I'm sure several
> of us have written our own version, but, to my
> surprise--astonishment!--I can't put my hands on one
> of them in public space just now.
>
> I'm late for a meeting myself; I'll summarize:
> A. You do NOT need to have after()s all
> over the widget tree, although I can
> understand the confusion;
> B. All that's necessary is a single
> "free-running" after() *that
> invokes itself*; and
> C. After I get out of my meetings, I'll
> write an example.
.
.
.
I need to put this minimal example of after()-based polling in the Wiki ...
import Tkinter
import time
root = Tkinter.Tk()
def my_update():
display.set("The time now is '%s'." % time.asctime(time.localtime()))
# Re-invoke myself in two seconds.
root.after(2000, my_update)
display = Tkinter.StringVar()
window = Tkinter.Label(root, textvariable = display)
window.pack()
my_update()
root.mainloop()
The effect is to create a textual clock which updates every two seconds,
while keeping the window "live".
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss