So my friend challenged me to make something with Python. I haven't really done Python before, so I'm struggling with quite a few things.
I have a 9 buttons
turn7 = Button(root, text='', relief="flat", font=("arial", 28, "bold"), width=3, command=lambda: doTurn(turn7,7))
I create every one of the buttons like this and then append them in a list:
_list.append([turn1,turn2,turn3,turn4,turn5,turn6,turn7,turn8,turn9])
I'm trying to change the text of all the buttons like this:
for turn in _list:
turn["text"] = "Text"
But it returns: "TypeError: list indices must be integers or slices, not str"
I have no idea what to do.
Thanks in advance.
The problem is that your list looks like [[turn1,turn2,turn3,turn4,turn5,turn6,turn7,turn8,turn9]]
, not [turn1,turn2,turn3,turn4,turn5,turn6,turn7,turn8,turn9]
. Use _list += [turn1,turn2,turn3,turn4,turn5,turn6,turn7,turn8,turn9]
instead. Hope that's helpful!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.