I seem to running into this "tuple index out of range error" when trying to create rectangle of random sizes. Before, I only had the color set to random and it works. However, when I tried to set the coordinates to random, I get an error and nothing appears on the canvas. Is there something that I am missing?
from tkinter import *
root = Tk()
import random
canvas = Canvas(root, width=550, height=400)
canvas.pack()
coord = [30, 40, 130, 140]
color = ["red", "orange", "yellow", "green", "blue", "violet"]
for j in range(10):
rectangle = canvas.create_rectangle(x0 = random.choice(coord) +j*5,
y0 = random.choice(coord)+j*5,
x1 = random.choice(coord)+j*5,
y1 = random.choice(coord)+j*5,
outline="black",
fill = random.choice(color))
Aucun commentaire:
Enregistrer un commentaire