I am trying to develop an app using pygame and I want to create a popup window.
I am trying to keep it all in one file, so I am using multiprocessing
for this task.
I have two classes, the app and the popup window. Each one is inside a function that creates the windows and start both of their loops.
This is some simplified code:
main.py
from multiprocessing import Process
def popup():
import pygame as pg
pg.init()
class PopUp:
def __init__(self):
self.screen = pg.display.set_mode((300,300))
def update(self):
pg.display.flip()
p = PopUp()
while True:
p.update()
def app():
import pygame as pg
pg.init()
class App:
def __init__(self):
self.screen = pg.display.set_mode((800,600))
self.create_popup()
def create_popup(self):
p = Process(target=popup)
p.start()
p.join()
def update(self):
pg.display.flip()
a = App()
while True:
a.update()
if __name__ == '__main__':
a = Process(target=app)
a.start()
a.join()
However, when I execute this code, only one window appears, with the size of the App, and then is resized to the size of the PopUp, even though it is a different process.
If I do it this other way, then two separate windows will appear with no problem at all.
Why is this happening and how can I get to create the popup window from the app class?