Tkinter Label, TypeError: cannot concatenate 'str' and 'instance' objects
Question: I am coding a dice simulator that will roll either a 6 sided dice or an 8
sided dice. I am using Python 2.7 and Tkinter. Here is my file with a
dictionary with the dice in:

    
    
    DICE = dict(
        sixsided={'name': 'Six Sided Dice',
                  'side': 6},
        eightsided = {'name': 'Eight Sided Dice',
                      'side': 8}
        )
    names = ['Six Sided Dice', 'Eight Sided Dice']
    

And here is the code from my main file that is causing my problem:

    
    
    diceroll = random.randrange(1,DICE[selecteddice]["side"])
    Label(diceroll, text="You rolled a " + diceroll + " on the " + DICE[selecteddice]["name"])
    

My problem is the error message that occurs when I run my file:

TypeError: cannot concatenate 'str' and 'instance' objects

Any help is greatly appreciated!! :)


Answer: Hope you were expecting something like this:

![Example window](http://i.stack.imgur.com/nL5HW.png)

You have to pass the `Tk()` class _assuming it was imported as`from Tkinter
import *`_ as the first argument to a Tk widget:

    
    
    root = Tk()
    Label(root, text="You rolled a " + diceroll + " on the " + DICE[selecteddice]["name"])
    

But now you'll end up with `TypeError: cannot concatenate 'str' and 'int'
objects` so use the `str()` method to convert `diceroll` to a string

    
    
    Label(root, text="You rolled a " + str(diceroll) + " on the " + DICE[selecteddice]["name"])
    

**`TypeError: cannot concatenate 'str' and 'instance' objects` error occurs
because data cannot be retrieved as strings or int's from a class without
using `__repr__` , `__str__` methods** _but rather as objects_

since you haven't displayed your full code this is far as I can help

    
    
    #The top image was produced thanks to this
    import random
    from Tkinter import *
    
    selecteddice = 'sixsided'
    
    DICE = dict(
        sixsided={'name': 'Six Sided Dice',
                  'side': 6},
        eightsided = {'name': 'Eight Sided Dice',
                      'side': 8}
        )
    names = ['Six Sided Dice', 'Eight Sided Dice']
    
    root = Tk()
    
    diceroll = random.randrange(1,DICE[selecteddice]["side"])
    Label(root, text="You rolled a " + str(diceroll) + " on the " + DICE[selecteddice]["name"]).pack()
    
    root.mainloop()
    

