tkinter and pygame do not want to work in one window [duplicate]

只愿长相守 提交于 2021-01-28 21:12:03

问题


I want to create an application and want to use tkinter as GUI and one of game libraries as Pyglet and Pygame. I didn't find any info about embedding pyglet into tkinter but found some code with tkinter and pygame: Embedding a Pygame window into a Tkinter or WxPython frame. I'm using python 3.7 and here is the code that I use:

import pygame
import tkinter as tk
from tkinter import *
import os


root = tk.Tk()
embed = tk.Frame(root, width=500, height=500)
embed.grid(columnspan=600, rowspan=500)
embed.pack(side=LEFT)
buttonwin = tk.Frame(root, width=75, height=500)
buttonwin.pack(side=LEFT)
os.environ['SDL_WINDOWID'] = str(embed.winfo_id())
os.environ['SDL_VIDEODRIVER'] = 'windib'
screen = pygame.display.set_mode((500, 500))
screen.fill(pygame.Color(0, 255, 255))
pygame.display.init()
pygame.display.update()


def draw():
    pygame.draw.circle(screen, (0, 0, 0), (250, 250), 125)
    pygame.display.update()
    button1 = Button(buttonwin, text='Draw', command=draw)
    button1.pack(side=LEFT)
    root.update()


while True:
    pygame.display.update()
    root.update()

It creates 2 windows when I want to create only one. What is going wrong? Thanks!


回答1:


Thanks to acw1668! Here you can download 1.9.6 pygame wheels: https://pypi.org/project/pygame/1.9.6/#files. And everything works fine with python 3.8!



来源:https://stackoverflow.com/questions/65735496/tkinter-and-pygame-do-not-want-to-work-in-one-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!