[Tkinter-discuss] Filling a series of tk.Label

Madhu Subramaniam madhu.subramaniam at gmail.com
Tue Mar 17 20:44:26 CET 2009


Iain,

I made a small test program (Fairly new in Tkinter), i have not found the
solution but i came across something, maybe somebody can throw more light on
this ?

Test Code (Active Python IDE 2.6 , Windows XP, Tkinter 8.4)

import sys
import pdb
from Tkinter import *
headers='ll'
machines= 'zt'
lbl = [[0]*len(headers)]*len(machines)
flag=0
root = Tk()
for i in range(len(machines)):
   for j in range(len(headers)):
    lbl[i][j] = Label(root, text= str(i)+str(j), bg = 'red')
    lbl[i][j].grid(row=i, column=j, padx=10, pady =5)
*print lbl # something that was noticed*
#print lbl[0][1]
lbl[0][0].config(text= 'row=0, column=0') # changes the text in lbl [1] [0]
lbl[0][1].config(text= 'row=0, column=1') # changes the text in lbl [1] [0]
lbl[1][0].config(text= 'row=1, column=0')# overwrites the text in lbl [1]
[0]
lbl[1][1].config(text= 'row=1, column=1') # overwrites the text in lbl [1]
[0]
root.mainloop()

*OUTPUT*
>>> [[<Tkinter.Label instance at 0x012B3B70>, <Tkinter.Label instance at
0x012B3AA8>], [<Tkinter.Label instance at 0x012B3B70>, <Tkinter.Label
instance at 0x012B3AA8>]]

The instances generated in row wise are the same, but within a row they are
different...
something more can be learnt from that?? hmm, i got to leave now.

Thanks
Madhu


On Tue, Mar 17, 2009 at 9:55 AM, Michael O'Donnell
<michael.odonnell at uam.es>wrote:

> Iain,
>
>  You code is incomplete, the place where you create the Label widgets
> is not included. We need that to see the problem.
>
> Check the grid operation on each Label, in particular the row parameter.
>
> Also, do a print as each Label is gridded, to see if they all are
> actually created.
>
> Mick
>
> On Mon, Mar 16, 2009 at 10:50 PM, Iain Day
> <iain at day-online.org.uk.invalid> wrote:
> > Hi,
> >
> > I've written a short program which is supposed to populate a table
> > constructed from tk.Label widgets. It does this by looping over the rows.
> > Unfortunately, it only seems to populate the final row. What am I doing
> > wrong?
> >
> > The code is:
> >
> > def updatedata():
> >    updatetime.delete(0, tk.END)
> >    for i in range(len(machines)):
> >        print machines[i]
> >        status = sshshowstat(machines[i])
> >
> >        for j in range(len(status)):
> >            param, value = status[j].split(': ')
> >
> >            for k in range(len(variables)):
> >                if re.match(variables[k], param) is None:
> >                    continue
> >                else:
> > #                    print i, value
> >                    if value in ('Acquiring', 'Regulated'):
> >                        systemdata[i][k].config(text=value,
> > foreground='green')
> >                    elif value in ('Not Reg.'):
> >                        systemdata[i][k].config(text=value,
> foreground='red')
> >                    else:
> >                        systemdata[i][k].config(text=value)
> >
> >
> > tk.Button(root, text="Update Table Data",
> > command=updatedata).grid(row=len(machines)+1, column=len(variables),
> > sticky=tk.S)
> >
> >
> >
> > Thanks,
> >
> > Iain
> >
> > _______________________________________________
> > Tkinter-discuss mailing list
> > Tkinter-discuss at python.org
> > http://mail.python.org/mailman/listinfo/tkinter-discuss
> >
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20090317/f1863ff9/attachment.htm>


More information about the Tkinter-discuss mailing list