Advertisement
here2share

# Tk_1200x680_Each_Pixel_A_Random_Color_Test_5.py

Apr 4th, 2021
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. # Tk_1200x680_Each_Pixel_A_Random_Color_Test_5.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import multiprocessing as mp
  6. from random import randint as rnd
  7. import time
  8.  
  9. def oRGB(rgb): # pass
  10.     r,g,b = rgb
  11.     return "#%02x%02x%02x" % (r,g,b)
  12.  
  13. ww = 1200
  14. hh = 680
  15. root = Tk()
  16. root.title("Tk_1200x680_Each_Pixel_A_Random_Color_Test_5")
  17. root.geometry("%dx%d+0+0"%(ww,hh))
  18. canvas = Canvas(root, width=ww, height=hh)
  19. canvas.grid()
  20.  
  21. img = Image.new("RGB",(ww, hh))
  22.  
  23. def my_function():
  24.     result = []
  25.     for z in range(ww):
  26.         result += [tuple(rnd(0,255) for rgb in 'rgb')]
  27.     return result
  28.  
  29. def get_result(result):
  30.     pix.extend(result)
  31.  
  32. if __name__ == '__main__':
  33.     while 1:
  34.         pix = []
  35.         pool = mp.Pool(mp.cpu_count())
  36.         for i in range(0, hh):
  37.             pool.apply_async(my_function, args=(), callback=get_result)
  38.         pool.close()
  39.         pool.join()
  40.         img.putdata(pix)
  41.         imgTk = ImageTk.PhotoImage(img)
  42.         canvas.create_image(0, 0, anchor=NW, image=imgTk)
  43.         canvas.update()
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement