printing slowly (Simulate typing)

前端 未结 4 1156
悲哀的现实
悲哀的现实 2020-12-05 21:35

I am trying to make a textual game in python. All goes well however, I would like to make a function that will allow me to print something to the terminal, but in a fashion

4条回答
  •  -上瘾入骨i
    2020-12-05 22:19

    Try this:

    def print_slow(str):
        for letter in str:
            sys.stdout.write(letter)
            sys.stdout.flush()
            time.sleep(0.1)
    
    print_slow("Type whatever you want here")
    

提交回复
热议问题