I am trying to create a program that has a tkinter window open, and then when you push a button, it closes the tkinter window and opens a pygame window. However, when I click the button to open the pygame window, it opens the pygame window and the tkinter window stays open.
Code:
import tkinter as tk
import pygame
root = tk.Tk()
btn = tk.Label(root, text="Start")
btn.bind("<Button-1>", lambda x: root.quit())
btn.pack()
root.mainloop()
root.destroy()
win = pygame.display.set_mode((500, 500))
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
win.fill((255, 255, 255))
pygame.display.update()
pygame.quit()
I have also tried using:
btn.bind("<Button-1>", lambda x: root.destroy())
btn.bind("<Button-1>", root.quit)
btn.bind("<Button-1>", root.destroy)
btn.bind("<Button-1>", lambda: root.quit())
btn.bind("<Button-1>", lambda: root.destroy())
def start(event=None):
root.quit()
btn.bind("<Button-1>", start)
How can I fix this? (I'm running Python 3.7.7 on MacOS 11.1)
from Tkinter window and pygame window open at same time
No comments:
Post a Comment