【发布时间】:2021-03-03 22:12:55
【问题描述】:
当屏幕上出现特定数字时,我正在尝试更改背景颜色 我正在使用乌龟使数字出现在屏幕上。问题是每当数字出现在屏幕上然后颜色改变数字就会暂停。我希望颜色每 30 秒改变一次。
import turtle
import random
#font on Screen
font_setup = ("Arial", 20, "normal")
#backgoround colors
background_colors = ["red", "blue", "green", "orange", "purple", "gold", "azure","beige", "yellow"]
wn = turtle.Screen()
#turtle for timer
counter = turtle.Turtle()
counter.goto(-100,180)
counter.pu()
counter.ht()
#random
cc = random.randint(1,10)
#counter and the background defnition, might be the cause of the problem
counter_interval = 1000
timer = 300
f = 0
famloop = True
def background_change():
global f
while famloop:
wn.bgcolor(background_colors[cc])
f -= 1
def countdown():
global timer, timer_up
counter.clear()
if timer <= 0:
counter.write("Time's Up", font=font_setup)
timer_up = True
else:
#background_change()
counter.write("Timer: " + str(timer), font=font_setup)
if timer == 290:
wn.bgcolor(background_change())
if timer == 280:
wn.bgcolor(background_change())
timer -= 1
counter.getscreen().ontimer(countdown, counter_interval)
wn.ontimer(countdown, counter_interval)
wn.listen()
wn.mainloop()
【问题讨论】:
-
这可能不合适,但是关于您刚刚删除的帖子和您的猜数字游戏,您可能想在codereview.stackexchange.com 上发布您的代码,这真的很有帮助;)
标签: python turtle-graphics python-turtle