I’m trying to create a preview window or sorts, for a game engine. I’ve already asked how to embed a window, and keep getting the same answer, to not mix frameworks. What I’m not trying to do, is mix frameworks. I just want to be able to render a pygame window within a pyqt5 window. They can remain seperate, they don’t have to be able to use the same app loop, but at the bare minimum I want to be able to see the pygame window within a pyqt5 widget.
Approaches can differ and it doesn’t necessarily have to be a through windows, It could be a web based approach for all I care. I just want to be able to show a pygame window within a pyqt5 widget like so.
Here’s something that I tried in tkinter
import tkinter as tk
import pygame
import os, random
root = tk.Tk()
button_win = tk.Frame(root, width = 500, height = 25)
button_win.pack(side = tk.TOP)
embed_pygame = tk.Frame(root, width = 500, height = 500)
embed_pygame.pack(side = tk.TOP)
os.environ['SDL_WINDOWID'] = str(embed_pygame.winfo_id())
os.environ['SDL_VIDEODRIVER'] = 'windib'
print(str(embed_pygame.winfo_id()))
pygame.display.init()
screen = pygame.display.set_mode()
def random_color():
global circle_color
circle_color = pygame.Color(0)
circle_color.hsla = (random.randrange(360), 100, 50, 100)
random_color()
color_button = tk.Button(button_win, text = 'random color', command = random_color)
color_button.pack(side=tk.LEFT)
def pygame_loop():
screen.fill((255, 255, 255))
pygame.draw.circle(screen, circle_color, (250, 250), 125)
pygame.display.flip()
root.update()
root.after(100, pygame_loop)
pygame_loop()
tk.mainloop()
RedEgs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.