我正在为Python中的tkinter开发一款游戏的程序,并且此刻一直试图制定一个“返回主菜单”按钮,但无济于事。请帮我一下吗?返回菜单按钮TKinter
这里是我到目前为止的代码:
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()
请不要_not_删除像你的问题的文本,它已经回答了。堆栈溢出是问题和答案的存储库,为未来的读者带来好处,而不仅仅是提出问题的人。 –