Tkinter Question
Martin Franklin
mfranklin1 at gatwick.westerngeco.slb.com
Thu Jun 16 04:07:07 EDT 2005
Fredrik Lundh wrote:
> Nicholas.Vaidyanathan at aps.com wrote:
>
>
>>Thanks for all the help guys... I'm a bit confused as to the inner
>>workings of the Tkinter system (I'm both a Python and a GUI n00b). I was
>>hoping that by slapping the x on button python was doing some cool
>>dynamic variable creation (i.e. creating 9 variables with 1 loop using
>>the x as a variable to modify the identifier), but I suppose you can't
>>do that in Python (or can you?)
>
>
> that's what lists are for (see the python tutorial for details).
>
A short explanation using a standard python list to hold the instances
of Tkinter Buttons:
buttonlist = []
for a in range(10):
b = Tkinter.Button(root, text=a)
b.pack()
buttonlist.append(b)
....
later
....
print buttonlist[2]["text"]
>
>>I'm a little confused as to why self.button.text doesn't work but
>>self.button["text"] does, can someone explain this?
>
>
> x.text and x["text"] are two different operations in Python, and
> Tkinter uses the former for widget methods, and latter for widget
> options.
>
> (w[x] is a shortcut for x.cget(x), btw)
>
> </F>
>
>
>
More information about the Python-list
mailing list