I'm developing a program for a game in tkinter on Python, and have been trying to formulate a 'Return to Main Menu' button at the moment, but to no avail. Please could I have some help?
Here is my code so far:
from tkinter import *
from tkinter import ttk
root = Tk()
def MainMenu():
GameButton = Button(root, text="New Game", command = NewGame)
GameButton.pack()
GameLabel = Label(root, text="Click to create a new 2-player game", fg="blue", font=("Helvetica",16))
GameLabel.pack()
HelpButton = Button(root, text="Help", command = Help)
HelpButton.pack()
HelpLabel = Label(root, text="Click if you would like instructions", fg="orange", font=("Helvetica",16))
HelpLabel.pack()
ExitButton = Button(root, text="Exit",command = exit)
ExitButton.pack()
ExitLabel = Label(root, text="Click to exit application", fg="red", font=("Helvetica",16))
ExitLabel.pack()
InstructionsLabelFunc.pack_forget()
ReturnMenuFunc.pack_forget()
def NewGame():
GameButton.pack_forget()
ExitButton.pack_forget()
def Help():
GameButton.pack_forget()
HelpButton.pack_forget()
ExitButton.pack_forget()
GameLabel.pack_forget()
HelpLabel.pack_forget()
ExitLabel.pack_forget()
InstructionsLabel = InstructionsLabelFunc
InstructionsLabel.pack()
ReturnMenu = ReturnMenuFunc
ReturnMenu.pack()
def Exit():
exit()
GameButton = Button(root, text="New Game", command = NewGame)
GameButton.pack()
GameLabel = Label(root, text="Click to create a new 2-player game", fg="blue", font=("Helvetica",16))
GameLabel.pack()
HelpButton = Button(root, text="Help", command = Help)
HelpButton.pack()
HelpLabel = Label(root, text="Click if you would like instructions", fg="orange", font=("Helvetica",16))
HelpLabel.pack()
ExitButton = Button(root, text="Exit",command = exit)
ExitButton.pack()
ExitLabel = Label(root, text="Click to exit application", fg="red", font=("Helvetica",16))
ExitLabel.pack()
InstructionsLabelFunc = Label(root, text="""
Taken from nrich.maths.org
This is a collection of games of skill for two players, both players have exactly the same information, chance plays no part, and each game must terminate. There is always a 'winning strategy' and all the moves can be analysed mathematically. The only advantage that either player can possibly have is to start or to play second. To work out how to win you need to start by analysing the 'end game', and the losing position to be avoided, and then work back to earlier moves. Can you find the winning strategies?
The rules are simple. Start with any number of counters in any number of piles. Two players take turns to remove any number of counters from a single pile. The winner is the player who takes the last counter.""", fg="black", font=("Calibri", 14))
ReturnMenuFunc = Button(root, text="Return to Main Menu", command = MainMenu)
InstructionsLabelFunc.pack_forget()
ReturnMenuFunc.pack_forget()
mainloop()