使用来自另一个问题的一些代码,我在 tkinter 窗口中嵌入了一个 pygame 窗口,我正在尝试制作一个在 pygame 窗口上绘制一个圆圈的 tkbutton,已经试验了一段时间,到目前为止还没有任何结果。任何想法都会很棒!这是我到目前为止的代码......
import Tkinter as tk
import os
import pygame as py
# R G B
red = (225, 0, 0)
green = (0, 255, 0)
w, h = 500, 200
p = False
def maketrue(p):
p = True
returnp
root = tk.Tk()
window = tk.Frame(root, width=w, height=h)
window.pack()
os.environ['SDL_WINDOWID'] = str(window.winfo_id())
root.update
py.display.init()
screen = py.display.set_mode((w, h))
screen.fill(py.Color(255, 0, 0))
drawbutton = tk.Button(root, text='Draw Circle', command = maketrue(p))
drawbutton.pack()
while True:
if p == True:
py.draw.circle(screen, red, (250, 50), 20)
py.display.update()
else:
pass
py.draw.circle(screen, green, (250, 100), 20)
root.update()