I have made a snakes and ladders program and want the game to end once someone has won. I did research and found out if I use the code below it should force close the program.
diceWindow = Tk()
diceWindow.destroy()
The window does close but errors come up:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 1550, in __call__
return self.func(*args)
File "/Users/user/Documents/Python /snakes and ladders.py", line 172, in numup
whosgoisit()
File "/Users/user/Documents/Python /snakes and ladders.py", line 176, in whosgoisit
btnRoll = Button(diceWindow, text="Roll", command=rolltwosDice(), width =20)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2209, in __init__
Widget.__init__(self, master, 'button', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2139, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: can't invoke "button" command: application has been destroyed.
How can I force close the program without the error coming up.
The code mentioned in the error is for the dice:
def numup():
global count
count += 1
whosgoisit()
def whosgoisit():
if (count % 2 == 0): #even
btnRoll = Button(diceWindow, text="Roll", command=rolltwosDice(), width =20)
else: #odd
btnRoll = Button(diceWindow, text="Roll", command=rollonesDice(), width =20)
btnRoll = Button(diceWindow, text="Roll", width=20, command=numup)
btnRoll.grid(row=100,column=0,columnspan=10)