【发布时间】:2019-09-22 05:44:59
【问题描述】:
我有一个程序,它接受用户的输入并使用Population() 函数显示输入的多种变体。 store_fit 函数将这些不同的变体添加到列表中,然后将它们删除,以便列表一次仅填充一个变体。
我希望能够从列表中获取变体并使用它来更新我的文本。但是,我的程序仅在 Population 函数完成后更新文本。如何运行Population 函数并同时更新我的文本?
代码:
fit = []
...
def store_fit(fittest): # fittest is each variation from Population
clear.fit()
fit.append(fittest)
...
pg.init()
...
done = False
while not done:
...
if event.key == pg.K_RETURN:
print(text)
target = text
Population(1000) #1000 variations
store_fit(value)
# I want this to run at the same time as Population
fittest = fit[0]
...
top_sentence = font.render(("test: " + fittest), 1, pg.Color('lightskyblue3'))
screen.blit(top_sentence, (400, 400))
【问题讨论】: