Reputation: 19264
I am currently making a monopoly game, and I want to display what my players roll in a label. I have a file dice.py, which has a function roll that rolls the dice (using random.randint(1,6)
twice, and adding them). I use a while True
just to test it out, but it gives me this error:
TypeError: 'int' object does not support item assignment
when I do
str = ''
strlabel = canvas.create_text(553, 275, text = str, fill='snow3', font=('Times New Roman', 24))
while True:
roll = dice.roll()
str = 'You just rolled a %d!' %(roll)
strlabel["text"] = "hey"
var2 = raw_input()
The raw_input just makes a pause in between each roll. I can't find much on Tkinter out there, so could someone tell me the update text syntax?
Upvotes: 0
Views: 117
Reputation: 739
The canvas.create_text doesn't create a new label. It create a new item (text) in the canvas and return the id (an int) of the created item.
You have to use the itemconfigure method to configure the item :
canvas.itemconfigure(strlabel, text='You just rolled a %d!'%(roll))
Upvotes: 2