我喜欢在等待一段时间后输出每一个字符串的字母,以获得打字机的效果。
for char in string:
libtcod.console_print(0,3,3,char)
time.sleep(50)但是这会阻塞主线程,程序就会变成非活动的。
你不能再访问它直到它完成
注意:使用http://doryen.eptalys.net/libtcod/
发布于 2013-05-22 12:42:59
除非有什么事情阻止你这样做,就把它放在一个线程中。
import threading
import time
class Typewriter(threading.Thread):
def __init__(self, your_string):
threading.Thread.__init__(self)
self.my_string = your_string
def run(self):
for char in self.my_string:
libtcod.console_print(0,3,3,char)
time.sleep(50)
# make it type!
typer = Typewriter(your_string)
typer.start()
# wait for it to finish
typer.join()这将防止睡眠阻塞你的主要功能。
线程的文档可以是在这里发现的。
一个不错的例子可以是在这里发现的
https://stackoverflow.com/questions/16691576
复制相似问题