0

I am trying to make a game, at the end of the game I want it to bring up a window that says "You are" and then when you close that window, or maybe after a time limit, it will open another window with the character here's what I have tried:

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()

if you run Youare with the mainloop, Percy() won't run until the master window closes, if you run it without the mainloop, they both display at the same time, thus killing the suspense. What am I doing wrong?

Devon M
  • 751
  • 2
  • 9
  • 24
  • You really shouldn't be giving a variable (`Percy`) the same name as a function. That's not your problem, but you definitely want to fix it anyway. – abarnert Oct 24 '12 at 23:21
  • Meanwhile, it sounds like the code you've written already does what you want. Sure, after you change it, it no longer does what you want. So don't do that. If you're trying to do something more complicated—e.g., have an "on close" function on the `You_are` object that causes `Percy()` to fire—you have to write an event handler for that; there's no way TkInter can guess what events you want to trigger what behavior. – abarnert Oct 24 '12 at 23:23

1 Answers1

1

The usual way to avoid calling several mainloop is to do something like

def Youare(master):
    You_are = Toplevel(master)
    #...

master = Tk()
Youare(master)
master.mainloop()

Then you will have to bind an action on your first window, have a look at these answer.

Community
  • 1
  • 1
FabienAndre
  • 4,514
  • 25
  • 38