I am attempting to make a Yahtzee game that works entirely, from rolling dice to keeping track of score, using tkinter to create a GUI. Code as follows:
from random import randint
from tkinter import *
import tkinter as tk
numbers = [0,0,0,0,0] # for storing numbers obtained after each roll
a = tk.Tk()
a.title('Yahtzee')
def Home():
# not shown: clears the window, then adds a frame
# not shown: checkbuttons so user can choose which dice to not roll
# not shown: labels to display "rolled" numbers
bRoll = tk.Button(a,text='Roll Dice',command=rollDice(5))
bRoll.pack()
bExit = tk.Button(a,text='Quit',command=Exit())
bExit.pack()
a.mainloop()
def rollDice(n):
z = 0
for x in range(1,n+1):
y = randint(1,6)
numbers[z] = y
z=z+1
Home()
def Clear(): # clears any widgets in the tkinter window for the next screen
# not shown
def Exit(): # closes the program
a.destroy()
Home()
I have run into a problem, however: when I run the program, I get these two errors over and over until a recursion error stops the program:
File "C:\Users\skor8\Desktop\Python\YahtzeeAlt.py", line 32, in Home
bRoll = tk.Button(a,text='Roll Dice',command=rollDice(5))
File "C:\Users\skor8\Desktop\Python\YahtzeeAlt.py", line 45, in rollDice
Home()
I can tell what's happening, the functions keep calling each other. Problem is, they are calling each other without the button in Home being pressed. I just don't know how to fix this.
Any ideas?