2017-10-17 14 views
0

コードを実行するたびに、さまざまな色の円を塗りつぶす必要があります。ランダムな円にランダムな色を追加するには

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を使用する必要があります。

+2

申し訳ありませんが、私はあなたの関数の上に 'create_circle'と呼んでいたときにコメントしましたか? – byxor

+0

には、コードにインポートが含まれています。 'random'モジュール、' turtle'モジュールからインポートしましたか? 排他的な輸入をしましたか? – 0TTT0

+0

@ 0TTT0私はそれを編集しました。私はカメを使用しないことを好む。 –

答えて

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

解決済み!

関連する問題