shape_color = ['red', 'blue', 'green']
のような色のリストを作成し、そのリストを単一のonkey()
キーボード キーに割り当てて、そのキーを押すたびに色のリストを循環し、タートルの色を変更する方法があるかどうか疑問に思っていました。私のプログラムは Python タートル グラフィックスであり、カーソルを動かしてさまざまな形状を画面にスタンプします。
9452 次
2 に答える
0
shape_color = ['red', 'blue', 'green'] # list of colors
idx = 0 # index for color list
# Callback for changing color
def changecolor():
idx = (idx+1) % len(shape_color) # Increment the index within the list bounds
fillcolor(shape_color[idx]) # Change the fill color
# Register the callback with a keypress.
screen.onkey(changecolor, "c")
c
キーを押すたびに、塗りつぶしの色が変化し、定義したリストが循環します。
于 2012-09-05T03:46:21.567 に答える