简体   繁体   English

如何为随机圆添加随机颜色

[英]How to add random colors to random circles

I need to get a different colors filled in for the different size of the circles each time when I run the code. 每次运行代码时,我需要为不同的圆圈大小填充不同的颜色。

from graphics import*
from random import*
from time import*

circle_x=0
circle_y=0
colors =0

#Graphics Window
def main():
    win = GraphWin("Bubbles", 500,500)
    message = Text(Point(250,200),"Click anywhere to continue")
    message.draw(win)
    win.getMouse()
    message.undraw()
main()    

#Create Circle
def create():
    win = GraphWin("Bubbles", 500,500)
    for i in range (4):

    # Creating a random point for the x of the circle
        circle_x = randint(50,450)

    #Creating a random point for the y of the circle
        circle_y = randint(0,100)

        p = Point(circle_x,circle_y)

        radius_x = randint(3,20)
        c = Circle(p,radius_x)

        colors = ("salmon","red","blue","green","purple","orange","yellow")
        fill = choice (colors)

        c.draw(win)

I have done this far, but somehow the color does not get filled in. I need to use choice . 我到目前为止已经做完了,但是不知何故颜色没有被填充。我需要使用choice

colors = ("salmon","red","navy","steelblue","wheat","darkorange","yellow")
        fill = choice (colors)
        c.setFill(fill)
        c.draw(win)     

Solved the problem! 解决了问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM