Threading example using the graphics package

import random from graphics import * from threading import Thread
 * 1) Example of using two threads to have it snow

def black_snow(win): for i in range(10000000000000): p = Point(random.randint(0,199),random.randint(0,199)) p.setFill('black') p.draw(win)

def blue_snow(win): for i in range(10000000000000): p = Point(random.randint(0,199),random.randint(0,199)) p.setFill('blue') p.draw(win)

win = GraphWin

t1 = Thread(target=black_snow,args=[win]) t1.start t2 = Thread(target=blue_snow,args=[win]) t2.start

win.getMouse win.close


 * 1) Ending like this without properly killing the threads will cause an error
 * 2) But I suggest that we ignore that for now.