Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_parallel_pixels_threading.py
- from Tkinter import *
- from threading import Thread
- import time
- import random
- from PIL import Image, ImageTk
- root = Tk()
- root.title("Y-Axis-Parallel_Pixels")
- root.geometry("120x120")
- wi = 120
- he = 120
- w = Canvas(root, width=wi, height=he)
- w.pack()
- def thread_process(y,xy):
- for x in range(120):
- xy.append((0,random.randrange(y*2+15, 255),0)) # set the color accordingly
- #
- def draw():
- threads = []
- img = Image.new( 'RGB', (wi,he))
- xy = []
- for y in range(he):
- t = Thread(target=thread_process, args=(y,xy))
- t.start()
- threads.append(t)
- # join all 120 Y-Axis threads
- for t in threads:
- t.join()
- img.putdata(xy)
- img = ImageTk.PhotoImage(img)
- #time.sleep(0.02)
- w.create_image(0, 0, anchor=NW, image=img)
- root.update()
- draw()
- #
- draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement