Tkinter: some Labels not updating

Fredrik Lundh fredrik at pythonware.com
Tue Apr 20 06:01:02 EDT 1999


python at pinky.cchem.berkeley.edu wrote:
> My Tkinter window has a Canvas with a bitmap image in one Frame,
> pull down menus in another Frame, and a few Buttons and Labels.  The
> Labels are supposed to indicate the values of certain variables which
> change when the user clicks on the canvas.  The first Label changes,
> but the others don't, they stay fixed at the values they had when
> I created the Label.
> 
> Is there a trick here or something I don't get?
> 
> I first create the StringVar:
> 
> self.X1v=StringVar()
> 
> Then I initialize X1v:
> 
> self.X1v.set("X1: not entered")
> 
> Then I make a Label object
> 
> self.l1=Label(tb, textvariable=self.X1v)
> self.l1.pack(side=TOP)
> 
> Then in the mouse callback (yes, it gets run, I have it print to stdout)
> 
>         self.X1v.set("X1: Got It")
> 
> But no update of the text in the label happens.  Updates _do_ happen
> in another Label object that is in a Frame by itself.  Do I need a
> separate Frame for each Label?  Do I have too many Label objects?

as far as I can tell, your program should work.  which means that
there's probably something you forgot to tell us.  try to make a
small but complete program that illustrates the problem.

(btw, if nothing else helps, you could skip the textvariables and
use self.l1.config(text="X1: Got it") instead...)

</F>





More information about the Python-list mailing list