I created a simple game in pygame. Prior to starting the main game you can set some options in the start menu (tkinter root window "startMenu"). Then via button in the root window, you can start the game (pygame screen). Then within the main game you can open an options menu (another tkinter root window "optionsMenu"). I don't want to destroy the root window "startMenu" upon entering the main game since i want to get back to it after i close the main game. The problem i encountered is, that upon creating the second root window "optionsMenu" my main game freezes, even after closing this second root window. It unfreezes only after the first root window "startMenu" is closed aswell.
For now i settled with destroying the first root window "startMenu" upon entering the main game. Everything works fine that way (I can open and close the "optionsMenu" as many times as i want without freezing the main game). But as i mentioned earlier, i would like to keep the first root window "startMenu" for getting back to it after the main Game ended.
Is there an easy way to accomplish that? I hope someone can help me out on that, thanks in advance.
here's a minimalistic code of what my problem describes:
import tkinter as tk
from tkinter import ttk
import pygame as p
def command_startGame():
# startMenu.destroy() works with this line, but is not what i want
p.init()
screen = p.display.set_mode((600, 600))
clock = p.time.Clock()
rect = p.Rect((50, 50, 100, 100))
screen.fill((200, 200, 100))
screen.fill('red', rect)
running = True
while running:
for e in p.event.get():
if e.type == p.QUIT:
running = False
elif e.type == p.MOUSEBUTTONDOWN:
mousePos = p.mouse.get_pos()
if rect.collidepoint(mousePos):
optionsMenu = tk.Tk()
optionsMenu.mainloop()
clock.tick(30)
p.display.flip()
startMenu = tk.Tk()
button_startGame = ttk.Button(startMenu, text='Start Game', command=command_startGame, state='normal')
button_startGame.pack()
startMenu.mainloop()