python - Problems accessing Tkinter widgets in a list -
i'm trying write small program have list of labels , entry-fields using python , tkinter (see code below). adding widgets no problem. however, when want use method of 1 of instances (like insert() on 1 of entry-fields) can't figure out way it.
my code looks this:
from tkinter import * import random root = tk() attributes = {'strength':10, 'dexterity':10, 'constitution':10, 'intelligence':10, 'wisdom':10, 'charisma':10} entries = [] labels = [] = 0 in attributes: labels.append(label(root, text = a, justify = left).grid(sticky = w)) entries.append(entry(root).grid(column = 1, row = i)) = i+1 root.mainloop()
and have tried simple
entries[i].insert("text insert")
and
e = entry e = entries[i] e.insert...
but hasn't helped. i've seen other examples of people trying use object in list, , seems doing did in first attempt. have missed something?
thanks
entry(root).grid()
returns nonetype
object, storing in list none
. can create entry
widget first, call grid()
, append list.
from tkinter import * import random root = tk() attributes = {'strength':10, 'dexterity':10, 'constitution':10, 'intelligence':10, 'wisdom':10, 'charisma':10} entries = [] labels = [] i,a in enumerate(attributes): labels.append(label(root, text = a, justify = left).grid(sticky = w)) e = entry(root) e.grid(column=1, row=i) entries.append(e) entries[i].insert(insert,"text insert") root.mainloop()
Comments
Post a Comment