我正在爲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_刪除像你的問題的文本,它已經回答了。堆棧溢出是問題和答案的存儲庫,爲未來的讀者帶來好處,而不僅僅是提出問題的人。 –