我喜欢在等待一段时间后输出字符串的每个字母,以获得打字机效果。
for char in string:
libtcod.console_print(0,3,3,char)
time.sleep(50)
但这会阻塞主线程,并且程序会变为非活动状态。
在完成之前您无法再访问它
Note: libtcod http://doryen.eptalys.net/libtcod/ is used
除非有什么东西阻止你这样做,否则就把它放到一个线程中。
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()
这将防止睡眠阻塞您的主要功能。
线程的文档可以是在这里找到 http://docs.python.org/2/library/threading.html
一个不错的例子可以是在这里找到 http://www.ibm.com/developerworks/aix/library/au-threadingpython/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)