I'm creating a game app and it has a menu window then a separate game window. I'm trying to get a Tkinter window to act as the menu and a pygame window for the game however if the game is running, I cant use the menu (can't even close it). If I try I get a fatal error message:
Fatal Python error: PyEval_RestoreThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized
Current thread 0x00002afc (most recent call first):
File "c:\Users\James\Documents\6th form\comp sci\NEA- A Level\code\gametst.py", line 12 in main
File "c:\Users\James\Documents\6th form\comp sci\NEA- A Level\code\Menu.py", line 15 in chess
File "C:\Users\James\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884 in __call__
File "C:\Users\James\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1421 in mainloop
File "c:\Users\James\Documents\6th form\comp sci\NEA- A Level\code\Menu.py", line 22 in <module>
This is the minimum code to reproduce:
Menu:
from tkinter import *
import game
WIN = Tk()
WIN.geometry("200x200")
def f():
game.main()
button = Button(WIN, text="button", command=f)
button.pack()
WIN.mainloop()
game:
def main():
import pygame
pygame.init()
WIN = pygame.display.set_mode((200, 200))
run = 1
while run:
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = 0
pygame.quit()
Is there a way to do this so that I can use the menu and the game at the same time? thx for any help
also if you know a better way to import the game to the menu that would be great, not overly bothered about that though
pygamepart in a separate thread should suffice toomain()without anything else does it still produce the problem?main()there would be no menu to freeze up, to me it seems thatmain()with itswhileloop is blockingWIN.mainloop(), actually it would be rather unseen but he could try usingafter()loops to run pygame, couldn't he?