Discussion:
[Tutor] Tkinter
The Dildoge Gamer
2015-08-24 20:31:22 UTC
Permalink
First off, i dunno if im doing this right. Anyway, in tkinter, im making a
program to store statistics, attributes, ect, and whenever you press a
button labled "Add Attribute" it created a new text box, you have an
unlimited number of text boxes to use. The problem is; they all have the
same name, so the text you type in one of them is copied to all of the
others. My question: How do i make a value go up by one when a button is
clicked, and how do i treat somethings name(The something being the new
attribute you add) as a property, so that when a new one is made, its name
is "Att" and then whatever the value equals. Kinda like if you say -

HiDerr = "Hai"

Hue = "Hue"

print(HiDerr + Hue)

But with tkinter and GUI parts, or whatever you'd like to call it. Thanks.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-08-25 00:22:37 UTC
Permalink
Post by The Dildoge Gamer
unlimited number of text boxes to use. The problem is; they all have the
same name, so the text you type in one of them is copied to all of the
others. My question: How do i make a value go up by one when a button is
clicked, and how do i treat somethings name(The something being the new
attribute you add) as a property, so that when a new one is made, its name
is "Att" and then whatever the value equals. Kinda like if you say -
You really shouldn't do that. It gets awfully complicated very quickly.

Instead, use a list to store these text box references. You can then
access them using an index into the list.

Something like

textBoxes = []
...
newTB = TextBox(...)
textBoxes.append(newTB)
...
textBoxes[3].insert(END,'Fourth text box')
...
print(textboxes[1].get(...))
...

Alternatively you could use a dictionary and give each text
box a string or numeric key. But in this case I suspect a
list is a better fit for your situation.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Loading...