I'm trying to Add a method to create a random size and position rectangle and add it to the Python list created in my constructor, The colour of the rectangles are based on the rainbow colours (‘red’, ‘orange’ ‘yellow’ ‘green’, ‘blue’ and ‘purple’)
this is the current code I have, any help would be great thanks ! new here.
from tkinter import *
import random
root = Tk()
class Recta:
def __init__(self, height, width, colours = []):
self.height=80
self.width=100
def randomRects(self,canvas):
w = random.randrange(100)
h = random.randrange(80)
canvas.create_rectangle(0,0,h,w,fill='green')
frame = Frame(root, bg='grey', width=400, height=40)
frame.pack(fill='x')
frame = Frame(root, bg='grey', width=400, height=40)
frame.pack(fill='x')
button1 = Button(frame, text='Add Rect')
button1.pack(side='left', padx=10)
button2 = Button(frame, text='Remove Rect')
button2.pack(side='left')
button3 = Button(frame, text = 'Add Circle')
button3.pack(side = 'left')
button4 = Button(frame, text = 'Remove Circle')
button4.pack(side= 'left')
button5 = Button(frame, text= 'Add Arc')
button5.pack(side = 'left')
button6 = Button(frame, text = 'Remove Arc')
button6.pack(side ='left')
c = Canvas(root)
c.pack()
tes = Recta(10,20)
tes.randomRects(c)
root.mainloop()