SkyPlooM
May 19th, 2009, 12:22 PM
Hi,
I'm trying to program a python mini applet which I want it does something like this:
2, 3, 4...n buttons depending on the options.
When pressed, writes its value.
Well, I always have printed the last value from the array.
Here is the code:
from Tkinter import *
def writing():
print a
root = Tk()
cont = 0
texto=["a","b","c","d"]
for a in texto:
cont = cont + 1
elemento = Button(root, text=a, command=writing, justify=LEFT, width=25)
elemento.grid (row=cont, column=1, sticky=W)
root.mainloop()
The problem is I don't know how to associate the a value each time to the button and send it to writing.
Thanks and Cheers
I'm trying to program a python mini applet which I want it does something like this:
2, 3, 4...n buttons depending on the options.
When pressed, writes its value.
Well, I always have printed the last value from the array.
Here is the code:
from Tkinter import *
def writing():
print a
root = Tk()
cont = 0
texto=["a","b","c","d"]
for a in texto:
cont = cont + 1
elemento = Button(root, text=a, command=writing, justify=LEFT, width=25)
elemento.grid (row=cont, column=1, sticky=W)
root.mainloop()
The problem is I don't know how to associate the a value each time to the button and send it to writing.
Thanks and Cheers