Advertisement
here2share

# tk_putpixel.py

Jul 27th, 2022
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. # tk_putpixel.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5.  
  6.  
  7. ww = 200
  8. hh = 200
  9.  
  10. b = 128
  11. pixels = tuple([(r,g,b) for r in range(ww) for g in range(hh)])
  12.  
  13. root = Tk()
  14.  
  15. canvas = Canvas(root, width=ww, height=hh, background="black")
  16. canvas.pack()
  17.  
  18. img = Image.new('RGB', (ww, hh))
  19. img.putdata(pixels)
  20. tk_img = ImageTk.PhotoImage(img)
  21. canvas.create_image(0, 0, anchor=NW, image=tk_img)
  22. root.mainloop()
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement