使用来自另一个问题的代码,我在一个tkinter窗口中嵌入了一个pygame窗口,我试图制作一个在pygame窗口上绘制一个圆圈的tk按钮,一直在试验并避开'到目前为止,任何结果都没有。任何想法都会很棒!这是我到目前为止的代码......
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()
答案 0 :(得分:7)
这意味着做了一段时间,但我现在有时间,这是一些基本代码,程序制作一个tkinter窗口,然后在一个框架中嵌入一个pygame窗口,然后创建另一个框架并按下一个按钮按下该窗口时,调用一个函数告诉pygame在pygame窗口上绘制一个圆圈。
import pygame
import Tkinter as tk
from Tkinter import *
import os
root = tk.Tk()
embed = tk.Frame(root, width = 500, height = 500) #creates embed frame for pygame window
embed.grid(columnspan = (600), rowspan = 500) # Adds grid
embed.pack(side = LEFT) #packs window to the 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(255,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()