尝试使用随机变量来随机化颜色?获得语法错误。这可能吗? 如果这有用的话,这是代码的其余部分:
import graphics
import random
window= graphics.GraphWin("x", 600, 400)
stripes = input("How many stripes should be on the flag")
stripes = int(stripes)
count = 0
count = int(count)
P1=graphics.Point(0,0) #left corner - anchor point
for x in range(stripes): #loop for division of flag
col= random.randint(1,255)
stepdim = 400/stripes #size of divisions
shrink = count*stepdim
stepdim = int(stepdim)
stepdim = stepdim*10 #enlarge to an increment below the last
stepdim = stepdim-shrink
stepdim = int(stepdim)
P2=graphics.Point(600,stepdim) #bottom right corner - ever shrinking
outsiderec=graphics.Rectangle(P1,P2) #
outsiderec.setFill(Color rgb(100, col, 0)
outsiderec.draw(window)
count= count + 1
count= int(count)
window.getMouse()
window.close()
python 3.4如果有任何帮助的话。
答案 0 :(得分:0)
如果您想使用custom color,则需要使用color_rgb(100, col, 0)
代替Color rgb(100, col, 0)
请注意首先导入color_rgb
:from graphics import color_rgb