简体   繁体   中英

create a repeating pop-up window (tkinter)

def popup():
  global Qscreen
  QA = random.randint(0,1)
  Qscreen = Toplevel(screen)
  Qscreen.attributes("-fullscreen", True)
  Qscreen.attributes("-topmost", True)
  Qscreen.title("QUESTION")
  Label(Qscreen, text = questions[QA]).pack()
  Button(Qscreen, text = "o", command = answer).pack()
  screen.after(10000, destroy)

def answer():
  Qscreen.destroy()


def destroy():
  global Qscreen
  Qscreen.destroy()
  popup()

def Maze():
  tkinter_window = Tkinter_window()
  tkinter_window.run()

def play():
  popup()
  Maze()

I need the popup function to open a window every 10 seconds and close after the user has clicked a certain button. However when testing this I wasnt able to click the button on the popup window.

Try changing your code like this.


def Maze():
    tkinter_window = Tkinter_window()
    tkinter_window.run()

def answer():
    Qscreen.destroy()
    Maze()

def destroy():
    Qscreen.destroy()
    popup()

def play():
    popup()

play() # popup()
screen.mainloop()

The Maze is now created after user presses button.

You should now be able to click the button in the pop-up window

def popup():
  global Qscreen

  Qscreen = Toplevel(screen)
  Qscreen.attributes("-fullscreen", True)
  Qscreen.attributes("-topmost", True)
  Qscreen.title("QUESTION")

  QA = random.randint(0,1)
  Label(Qscreen, text = questions[QA]).pack()
  Button(Qscreen, text = "o", command = answer).pack()

  screen.after(10000, destroy)

def answer():
    Qscreen.destroy()
    Maze()

def destroy():
    Qscreen.destroy()
    popup()

def Maze():
    tkinter_window = Tkinter_window()
    tkinter_window.run()

def play():
    popup()

play()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM