Search code examples
pythonrendering

What Is The Most Basic Way To Render Pixels In Python?


How can I directly access the color of pixels and create windows in Python? I have found ways like Pillow and Turtle, but what are they built on? And what are the ones supporting them built on? I am looking for the most native and basic way to render pixels.

If this is not specific enough, then how can I directly make a window of size 100x100 and coordinates (0,0) on the screen and make a red box of size 10x10 in the middle of the screen and then clear the window and redraw the box 5 pixels to the right? I want to all of this without using a library to make it easier. Hopefully it is in a way where I could write my own library.

In turtle, the first render might look like this:

import turtle
turtle.hideturtle()
turtle.speed(0)
turtle.setpos(-5,-5)
turtle.setheading(90)
turtle.pencolor("red")
turtle.pensize(1)
turtle.pendown()
for _ in range(5):
    turtle.forward(10)
    turtle.right(90)
    turtle.forward(1)
    turtle.right(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(1)
    turtle.left(90)

Solution

  • What I was looking (though I would have been fine with something more basic) was that

    [TKinter] is the standard Python interface to the Tk GUI toolkit, and is Python's de facto standard GUI.

    From TKinter’s Wikipedia page.
    TKinter is Python’s most basic library for drawing and it is the only one built in to the standard library of Python.