I'm new at Python, trying to fill a canvas with random pixels. Could someone tell me why it's doing horizontal stripes?
import tkinter
from random import randint
from binascii import hexlify
class App:
def __init__(self, t):
x=200
y=200
xy=x*y
b=b'#000000 '
s=bytearray(b*xy)
c = tkinter.Canvas(t, width=x, height=y);
self.i = tkinter.PhotoImage(width=x,height=y)
for k in range (0,8*xy,8):
s[k+1:k+7]=hexlify(bytes([randint(0,255) for i in range(3)]))
print (s[:100])
pixels=s.decode("ascii")
self.i.put(pixels,(0,0,x,y))
print (len(s),xy*8)
c.create_image(0, 0, image = self.i, anchor=tkinter.NW)
c.pack()
t = tkinter.Tk()
a = App(t)
t.mainloop()
Which gives e.g.: