[Python] What's wrong with this tkinter script

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    I tried to make a script that gives you a menu for games in tkinter, but if i press Escape then nothing happend, no quit, no error, nothing. This is the script:

    from tkinter import Tk, Canvas, Button
    import pyautogui as p

    root = Tk()

    c = Canvas(root, width=400, height=400)

    def close(event):
    root2.destroy()

    def Game1():
    root.destroy()
    root2 = Tk()
    sx, sy = p.size()
    root2.attributes('-fullscreen', True)
    c2 = Canvas(root2, width=sx, height=sy, bg='green')
    c2.pack()
    root2.bind("<Escape>", close)
    root2.mainloop()

    b = Button(root, text='Play (game name 1)', command = Game1)

    b.pack()
    c.pack()
    root.mainloop()


    So what's wrong?

    i tried doing root2.destroy itself, i tried using other strings in the root2.bind and more

    i expect it to close if i press escape

    Continue reading...

Compartilhe esta Página