Random fill colour for shapes in Python(TKinter) Random fill colour for shapes in Python(TKinter) tkinter tkinter

Random fill colour for shapes in Python(TKinter)


de=("%02x"%random.randint(0,255))re=("%02x"%random.randint(0,255))we=("%02x"%random.randint(0,255))ge="#"color=ge+de+re+we

and in tkinter put

fill=color

easyyou can also make

fill="#"+("%06x"%random.randint(0,16777215))


You can use random.choice like this

import randomcolors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]canvas.create_rectangle(self.x, self.y, self.x + 60, self.y + 60, fill = random.choice(colors))

This will pass a random color to fill whenever this code is executed.


You can use choice, from package random

random.choice(color)