独立于平台的实时 canvas 绘图?

Platform-independent, real-time canvas drawing?

我想在 canvas 上实时绘图,可能设置单个像素,绘制矩形等几何形状,并插入图像。

这就是我想要的样子:

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)

任何更复杂或设置成本更高的东西都是不可接受的。我运气不好吗?

我还没有找到一个不需要我做的 GUI 框架的例子:

到目前为止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)