pygame帧渲染到tkinter窗口示例程序

"""
   pygame帧渲染到tkinter窗口示例程序.py
"""
import os
import pygame
from tkinter import *

root =  Tk()
root.title("pygame帧渲染到tkinter窗口示例程序")

# 创建左边框架,用于渲染pygame帧
left_frame =  Frame(root, width = 500, height = 500) 
left_frame.pack(side = LEFT) # 放于左边对齐

# 创建右边框架,用来放按钮
right_frame =  Frame(root, width = 75, height = 500)
right_frame.pack(side = LEFT)

# 指定渲染的窗口的id号
os.environ['SDL_WINDOWID'] = str(left_frame.winfo_id())
# os.environ['SDL_VIDEODRIVER'] = 'windib'
screen = pygame.display.set_mode((500,500))
screen.fill(pygame.Color(205,55,255))

def draw_circle():
     """ 画圆圈函数 """
     pygame.draw.circle(screen, (0,255,0), (250,250), 62)
     pygame.display.update()
    
button1 = Button(right_frame,text = '画圆圈',  command=draw_circle)
button1.pack(side=TOP)

def draw_rect():
    """ 画矩形函数 """
    pygame.draw.rect(screen, (222,0,0), (50,50,100,100))
    pygame.display.update()
    
button2 = Button(right_frame,text = '画矩形',  command=draw_rect)
button2.pack(side=TOP)

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