[英]Platform-independent, real-time canvas drawing?
I want to draw on a canvas in real time, possibly set individual pixels, draw geometric shapes like rectangles, and insert images. 我想在画布上实时绘制,可能设置单个像素,绘制矩形等几何形状,并插入图像。
This is what I want it to look like: 这是我想要的样子:
from greatgui import Window, Canvas
from time import sleep
width = 640
height = 480
w = Window("My title", (width,height))
c = Canvas((width, height))
w.add(c)
i = 0
while True:
c.putpixel((i, i), color=(255,255,255))
i += 1
w.update()
sleep(0.1)
Anything of greater complexity or setup cost is unacceptable. 任何更大的复杂性或设置成本都是不可接受的。 Am I down on my luck?
我很不走运吗?
I have not found a single example of a GUI framework that doesn't require me to: 我还没有找到一个不需要我执行以下操作的GUI框架示例:
So far https://www.pygame.org seems to be a good choice: 到目前为止, https://www.pygame.org似乎是一个不错的选择:
import pygame
from time import sleep
pygame.init()
pygame.display.set_caption("My title")
screen = pygame.display.set_mode((640,480))
background_color = (255, 255, 255)
i = 0
running = True
while running:
screen.fill(background_color)
pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(i, i, 40, 30))
i += 1
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.flip()
sleep(0.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.