Hi Guido,

On Thu, 01 Apr 2010 00:02:36 -0600
Guido Carballo-Guerrero <char...@me.com> wrote:

> Is it possible to display and update data using labels in a window,
> created by another window?
> 
> This is a program I did that is not working as expected:
> 
> 
(...)
> def newcount():
> 
>     root2 = Tkt.Tk()
>     var2 = Tkt.IntVar()
>     frameLabels2 = Tkt.Frame(root2)
>     frameLabels2.pack()
> 
>     def changeVal():
> 
>         var2.set(var2.get()+1)
>         print 'var2: ',var2.get()
>         
> 
>     Tkt.Label(frameLabels2,text='var2: ').pack(side=Tkt.LEFT)
>     Tkt.Label(frameLabels2,textvariable=var1).pack(side=Tkt.LEFT)
>     
>     Tkt.Button(root2,text="Change value", command=changeVal).pack()
>     root2.mainloop()

There are two problems in this function, first you should _never_ use
two instances of Tk() in one program; if you need a second window, use
a Tkinter.Toplevel() instead.
Second, you assign var1 as textvariable for the Label; I think what you
actually intended is to set the current value of var1 as initial value
for var2 and then use var2 as textvariable for the label ? If yes,
simply change the first lines of newcount() into:

def newcount():

    root2 = Tkt.Toplevel()
    var2 = Tkt.IntVar()
    var2.set(var1.get())

I hope this helps

Michael




_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to