0

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)
S2673
  • 269
  • 4
  • 15
  • 1
    https://stackoverflow.com/questions/12284311/python-tkinter-how-to-work-with-pixels Are you talking browser windows or OS windows or what? – JSRB Aug 28 '20 at 14:54
  • tkinter, pyqt, pywidgets,..... or OpenGL Python. GL writing the library yourself – rioV8 Aug 28 '20 at 15:04
  • 1
    Python itself doesn't have any concept of pixels, you need a library on top of it to deal with that. – Mark Ransom Aug 28 '20 at 15:24
  • @Jonas OS windows, I think. The same window that pops up with Turtle. I have looked at TKinter too, but is that as basic as it gets? – S2673 Aug 30 '20 at 15:31
  • @rioV8 Yes, writing the library myself is exactly what I want to do. I edited the question to say that. I do that with OpenGL? – S2673 Aug 30 '20 at 15:31
  • @Mark Ransom So what is the most basic library and what language will deal with pixels? – S2673 Aug 30 '20 at 15:32
  • There are many such libraries, all completely different. Recommending a library is specifically discouraged by SO. – Mark Ransom Aug 30 '20 at 16:35
  • @Mark But they can’t all be the most basic. So what are those libraries built on? – S2673 Aug 30 '20 at 17:10
  • 1
    C, probably.... – Mark Ransom Aug 30 '20 at 17:33
  • @Mark Then what C function can set the color of a pixel? – S2673 Aug 30 '20 at 17:35
  • C, like Python, doesn't have a concept of a pixel inherent to the language. You need to use a library or OS API. – Mark Ransom Aug 30 '20 at 18:35
  • If you want to write the library yourself than you are not allowed to use OpenGL because it is a library, you need to write the interface to the OpenGL API and Window interface yourself – rioV8 Aug 30 '20 at 18:45
  • @Mark What does have a concept of pixels? – S2673 Aug 30 '20 at 18:59
  • There are only so many times I can tell you. You don't seem to be capable of understanding. – Mark Ransom Aug 30 '20 at 21:31

1 Answers1

0

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.

S2673
  • 269
  • 4
  • 15