Advertisement
here2share

# Tk_parallel_pixels_threading.py ^2018.08

Aug 19th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. # Tk_parallel_pixels_threading.py
  2.  
  3. from Tkinter import *
  4. from threading import Thread
  5. import time
  6. import random
  7. from PIL import Image, ImageTk
  8.  
  9. root = Tk()
  10. root.title("Y-Axis-Parallel_Pixels")
  11. root.geometry("120x120")
  12. wi = 120
  13. he = 120
  14. w = Canvas(root, width=wi, height=he)
  15. w.pack()
  16.  
  17. def thread_process(y,xy):
  18.     for x in range(120):
  19.         xy.append((0,random.randrange(y*2+15, 255),0)) # set the color accordingly
  20. #
  21. def draw():
  22.     threads = []
  23.     img = Image.new( 'RGB', (wi,he))
  24.     xy = []
  25.     for y in range(he):
  26.         t = Thread(target=thread_process, args=(y,xy))
  27.         t.start()
  28.         threads.append(t)
  29.     # join all 120 Y-Axis threads
  30.     for t in threads:
  31.         t.join()
  32.     img.putdata(xy)
  33.     img = ImageTk.PhotoImage(img)
  34.     #time.sleep(0.02)
  35.     w.create_image(0, 0, anchor=NW, image=img)
  36.     root.update()
  37.     draw()
  38. #
  39.  
  40. draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement