我想按一个按钮后从某个帧重置我的程序。按下按钮时,它会提升前一帧,但会显示之前显示的标签/答案。我希望我能更好地解释这一点,但我不确定。我希望代码从'f4'开始设置这是代码,所以你可以自己看看:
from tkinter import *
import random
import time
root=Tk()
def returnEntry():
name=NameEntry.get()
label3.config(text= "Welcome, " + name)
f3.tkraise()
def changeLabel():
f4.tkraise()
label5.after(3000, label5.place_forget)
label6.after(6000, f5.tkraise)
label8.after(6000, label8.tkraise)
AskAgain.after(10000, AskAgain.tkraise)
f1 = Frame(root)
f2 = Frame(root)
f3 = Frame(root)
f4 = Frame(root)
f5 = Frame(root)
for frame in (f1, f2, f3, f4, f5):
frame.config(width=500,height=500, bg="light blue")
frame.place(relx=0.5,rely=0.5,anchor="center")
#First Page
Button(f1, text='Click to Play', command=f2.tkraise).place(relx=0.5,rely=0.5,anchor="center")
label1=Label(f1, text='Magic 8 Ball', fg="White", bg="dark blue",font="Veranda 19")
label1.place(relx=0.5,rely=0.20,anchor="center")
#Second page
label2=Label(f2, text='Enter your name:',fg="White", bg="dark blue",font="veranda 17")
label2.place(relx=0.5,rely=0.40,anchor="center")
NameEntry=Entry(f2,font="veranda 15")
NameEntry.place(relx=0.5,rely=0.5,anchor="center")
Button2=Button(f2, text='Continue', font="veranda 15",command=returnEntry)
Button2.place(relx=0.5,rely=0.60,anchor="center")
#Third Page
label3=Label(f3,bg="light blue",fg="black",font="veranda 15")
label3.place(relx=0.5,rely=0.35,anchor="center")
label4=Label(f3, text="Ask me a yes or no question and reveal the truth" , bg="light blue",font="veranda 15")
label4.place(relx=0.5,rely=0.45,anchor="center")
QuestionEntry=Entry(f3, font="veranda 15").place(relx=0.5,rely=0.52,anchor="center")
Button(f3, text='Ask away', command=changeLabel).place(relx=0.5,rely=0.6,anchor="center")
#Fourth Page
label5=Label(f4, text=random.choice(("Checking my database...", "Give me a second...","Calculating answer...")),font="veranda 15",bg="light blue")
label5.place(relx=0.5,rely=0.5,anchor="center")
label6=Label(f4, text=random.choice(("Hmm...","Let me see...","Thinking...")),font="veranda 15",bg="light blue")
label6.place(relx=0.5,rely=0.5,anchor="center")
label6.lower(belowThis=label5)
#Fith Page
label7=Label(f5,text="Answer:",font="veranda 15", bg="light blue")
label7.place(relx=0.5,rely=0.4,anchor="center")
label8=Label(f5,text=random.choice(("I wouldn't count on it", "100%", "Possibly",
"I'm afraid not", "That infomation is classified")), font="veranda 15", bg="light blue")
label8.place(relx=0.5,rely=0.5,anchor="center")
AskAgain=Button(f5, text="Ask another question", font="veranda 10",command=f3.tkraise)
AskAgain.place(relx=0.5, rely=0.6, anchor="center")
root.geometry("500x500")
root.title("Magic 8 Ball")
root.mainloop()
提前致谢。