每次运行代码时,我都需要为不同大小的圆圈填充不同的颜色。
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)
我已经做到了这一点,但不知怎的,颜色没有填补。
我需要使用choice
。
答案 0 :(得分:1)
colors = ("salmon","red","navy","steelblue","wheat","darkorange","yellow")
fill = choice (colors)
c.setFill(fill)
c.draw(win)
解决了问题!