Home > Mobile >  create a repeating pop-up window (tkinter)
create a repeating pop-up window (tkinter)

Time:12-18

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.

CodePudding user response:

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.

CodePudding user response:

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