It's my understanding that the class DiceRoller
should be inheriting from the class die
, however every time I run I get the error:
self.display.config(text = str(self.value))
AttributeError: 'DiceRoller' object has no attribute 'display'
The value of self.value
is updating, but the Tkinter label is not.
import Tkinter
import random
class die(object):
def __init__(self,value,display):
self.value = random.randint(1,6)
self.display = Tkinter.Label(display,
text = str(self.value),
font = ('Garamond', 56),
bg = 'white',
relief = 'ridge',
borderwidth = 5)
self.display.pack(side = 'left')
class DiceRoller(die):
def __init__(self):
self.gameWin = Tkinter.Tk()
self.gameWin.title('Dice Roller')
self.gameFrame = Tkinter.Frame(self.gameWin)
self.dice = []
self.Row1 = Tkinter.Frame(self.gameWin)
for i in range(1,4):
self.dice.append(die(i,self.Row1))
self.topFrame = Tkinter.Frame(self.gameWin)
self.rollBtn = Tkinter.Button(self.topFrame,
text = 'Roll Again',
command = self.rollDice,
font = ('Garamond', 56))
self.rollBtn.pack(side = 'bottom')
self.gameFrame.pack()
self.Row1.pack()
self.topFrame.pack()
self.gameWin.mainloop()
def rollDice(self):
self.value = random.randint(1,6)
print self.value #to show value is in fact changing
self.display.config(text = str(self.value))
varName = DiceRoller()