我正在尝试制作一款游戏,在游戏结束时,我希望它能打开一个窗口,上面写着“你是”然后当你关闭那个窗口,或者可能在一个时间限制之后,它会打开另一个这个角色的窗口是我试过的:
def Youare():
You_are= Toplevel()#I have tried making this Tk() as well
You_are.geometry('+700+100')
says = Label(You_are,text ='You are....',font=('Helvetica',74))
says.pack(side=BOTTOM)
You_are.mainloop()#If I take this out both windows display at the same time
def Percy():
Percy= Toplevel()
Percy.geometry('450x450')
says = Label(Percy,text ='We were just looking at maps')
says.pack(side=BOTTOM)
img = ImageTk.PhotoImage(Image.open('C:/Users/Geekman2/Pictures/Pictures/Percy.jpg'))
image1 = Label(Percy,image=img)
image1.pack()
Percy.mainloop()
Youare()
Percy()
如果你使用mainloop运行Youare,Percy()将不会运行,直到主窗口关闭,如果你在没有mainloop的情况下运行它们,它们都会同时显示,从而消除了悬念。我做错了什么?
答案 0 :(得分:1)
避免调用几个mainloop的常用方法是执行类似
的操作def Youare(master):
You_are = Toplevel(master)
#...
master = Tk()
Youare(master)
master.mainloop()
然后你必须在第一个窗口绑定一个动作,看看these answer。