TkInter: draw one pixel

In TkInter, we can draw multiple shapes . But what if we just want to draw a pixel instead?

+3


source to share


2 answers


After creating the object, Canvas

you can draw a line that spans one pixel.



your_canvas_widget.create_line(x, y, x + 1, y)

      

+2


source


To create a single pixel with coordinates x, y

on the canvas, you can use an object rectangle

:

canvas.create_rectangle( (x, y)*2 )

      



By default, a rectangle object has a one-pixel-wide black border, which, when one pixel wide, will only be black, regardless of color. To give the pixel the color you want, you can use outline=""

to then specify the color fill

.

I prefer this method as you only need to provide the coordinates x, y

, it is not required x+1

.

0


source







All Articles