tkinter canvas create_rectangle

from tkinter import *
import random

tk=Tk()
canvas=Canvas(tk, width=400,height=400)
canvas.pack()

def random_rectangle(width,height,fill_color):
    x1=random.randrange(width)
    y1=random.randrange(height)
    x2=random.randrange(x1+random.randrange(width))
    y2=random.randrange(y1+random.randrange(height))
    if abs(x1-x2)*abs(y1-y2)>20000:
        return
    if abs(x1-x2) <50 or abs(y1-y2)<50 :
        return
    canvas.create_rectangle(x1,y1,x2,y2,fill=fill_color,width=0)

colortable=("green","red","blue","orange",
            "yellow","pink","purple","violet","magenta","cyan")
for i in range(300):
    for colori in colortable:
            random_rectangle(400,400,colori)
            

コメント

このブログの人気の投稿

シェルピンスキーの三角形

global 変数・ローカル変数