On Wed, Jan 26, 2011 at 11:21 AM, Elwin Estle <chrysalis_reb...@yahoo.com>wrote:

> With Tcl/Tk, you can generate widgets "on the fly" during program
> execution, without having to explicitly create them in your code.  i.e.,
> something like:
>
> for {set i 0} {$i <= 5} {incr i} {
>     label .myLabel_$i -text "this is label myLabel_$i"
>     pack .myLabel_$i

}
>

for x in xrange(5):
    Label(root, text="This is label %d" %x).pack()

will generate the labels. You can't put the variable names in the local
namespace without some tricksy methods. You could, however, have a dict
labels and just do

labels[x] = Label(root, text="blah")
labels[x].pack()

HTH,
Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to