update of elements in GUI

Eric Brunel eric.brunel at pragmadev.nospam.com
Tue Aug 17 14:19:25 CEST 2010

(Top-post corrected; please don't do that, it makes messages very hard 
to read via usenetŠ)

In article 
<26c363c8-11d7-49b9-a1c1-251ab5ff934e at p22g2000pre.googlegroups.com>,
 Jah_Alarm <jah.alarm at gmail.com> wrote:
> On Aug 17, 7:19 pm, Eric Brunel <eric.bru... at pragmadev.nospam.com>
> wrote:
> > You have to call update_idletasks on a Tkinter *widget*, not a variable.
> > You can call it on your window (Tk or Toplevel instance) or on your
> > label for example. This way, it should work.
> >
> thanks. The thing is, the objects actually get updated without this
> command, but when I run the GUI outside of python shell (i.e. in
> command prompt as python filename.py or compile it to .exe file) the
> objects do not get updated. I tried
> Label(mainframe,textvariable=var).grid(column=1,row=1).update_idletasks()
> and mainframe.update_idletasks() but it still doesn't work.

I think you're really misunderstanding something here: the call to 
update_idletasks is a one shot call to the GUI to basically tell it to 
refresh itself. So each time you change anything that should be 
displayed, you have to call that method again, or your changes will only 
be seen when the control returns to the GUI, which is basically at the 
end of your processing.

The fact that it works when you're doing it interactively is normal. In 
this mode, you don't have a GUI event loop running, so the GUI updates 
itself all the time automatically. This is never true in programs you 
run the 'normal' way, i.e via: python filename.py

And by the way, Label(Š).grid(Š).update_idletasks() had no chance to 
work anyway: the grid method doesn't return anything, so you're trying 
to call the update_idletasks method on None hereŠ

 - Eric -

More information about the Python-list mailing list