2080
2080

Reputation: 1417

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:

Upvotes: 1

Views: 491

Answers (1)

2080
2080

Reputation: 1417

So far https://www.pygame.org seems to be a good choice:

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)

Upvotes: 2

Related Questions