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 = []):

    def randomRects(self,canvas):
        w = random.randrange(100)
        h = random.randrange(80)
        frame = Frame(root, bg='grey', width=400, height=40)
        frame = Frame(root, bg='grey', width=400, height=40)
        button1 = Button(frame, text='Add Rect')
        button1.pack(side='left', padx=10)
        button2 = Button(frame, text='Remove Rect')
        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)

tes = Recta(10,20)


Very nice program for python.

This may not work for the kind of program you're writing (I rarely use Tkinter, more often Pygame) but one thing you could do is use random.randint() and then convert the numbers gained from that into a variable, like so:

import tkinter
import random

leftcoords = random.randint(1000)
topcoords = random.randint(1000)

Obviously you would have to edit this to fit it into your program and Tkinter itself ( like I said, not a master) but this should give you a general idea.