So I am making a yahtzee game in python. I have it setup to roll the dice when you click the button. Then you can hold the number from rolling again by clicking on it. My goal is to assign the values from this range(5) to a variable. Preferably I hope that it would update the variable every time the dice button is clicked.
This is just for a game I have been working on for myself to get better with python. I have tried to think of a way to assign it to a dict but I have been unable to find out how.
from tkinter import *
from random import randint
root = Tk()
root.title("Sam's Yahtzee")
def roll(dice, times):
if times > 0:
dice['text'] = randint(1, 6)
root.after(10, roll, dice, times-1)
def roll_dices():
for i in range(5):
if dices[i][1].get() == 0:
# dice is not held, so roll it
roll(dices[i][0], 10)
dices = []
for i in range(5):
ivar = IntVar()
dice = Checkbutton(root, text=randint(1, 6), variable=ivar, bg='silver', bd=1, font=('Arial', 24), indicatoron=False, height=3, width=5)
dice.grid(row=0, column=i)
dices.append([dice, ivar])
Button(text='Dice', command=roll_dices, height=2, font=(None, 16, 'bold')).grid(row=1, column=0, columnspan=5, sticky='ew')
yahtzee = 0
threeKind = 0
fourKind = 0
fullHouse = 0
smallStraight = 0
largeStraight = 0
chance = 0
possibleHands = {"yahtzee": yahtzee,
"threeKind": threeKind,
"fourKind": fourKind,
"fullHouse": fullHouse,
"smallStraight": smallStraight,
"largeStraight": largeStraight,
"chance": chance}
root.mainloop()