from tkinter import * import random import webbrowser global u tk = Tk() #change and add more to the color list if needed! color = ['red','orange','yellow','green','blue','purple','violet','magenta','cyan'] canvas = Canvas(tk,width=400,height=400) tk.geometry('450x600') canvas.pack() tk.configure(bg='black') exitbutton = Button(tk,text="Exit Program",command=tk.destroy).pack() tk.title('Generated Program') tk.resizable(False,False) def rand_shape(width,height,fill_color,shape): x1 = random.randrange(width) y1 = random.randrange(height) x2 = random.randrange(x1 + random.randrange(width)) y2 = random.randrange(y1 + random.randrange(height)) if shape == "re": canvas.create_rectangle(x1,y1,x2,y2,fil=fill_color) elif shape == "li": canvas.create_line(x1,y1,x2,y2,fill=fill_color) def clear(): canvas.delete('all') def randomgenerator(): for z in range(1,100): u = random.randint(1,2) if u == 1: rand_shape(400,400,fill_color=color[random.randint(0,8)],shape='li') elif u == 2: rand_shape(400,400,fill_color=color[random.randint(0,8)],shape='re') retrybutton = Button(tk,text="Retry",command=randomgenerator).pack() clearbutton = Button(tk,text="Clear",command=clear).pack() xext = Label(tk,text="This Program Uses randrange and canvas to make a randomly \n generated artwork.").pack() for x in range(1,10): randomgenerator()