简体   繁体   English

如何删除和替换python中的打印文本?

[英]How to remove and replace printed text in python?

I'm creating a memory game in Python, where a grid of words is displayed for 20 seconds before being replaced by another grid, in which one of the words has been changed. 我正在用Python创建一个记忆游戏,其中一个单词网格显示20秒,然后被另一个网格替换,其中一个单词已被更改。 Currently, this grid is printed and then another grid is printed below. 目前,打印此网格,然后在下面打印另一个网格。

grid = [nineWordsRandom [j:j+3] for j in range(0, len(nineWordsRandom), 3)]

         for x,y,z in grid:

             print(x,y,z)

How could I remove this grid after 20 seconds and replace it with another grid? 如何在20秒后删除此网格并将其替换为另一个网格? Thanks. 谢谢。

Here You have a simple program using the curses module , that pretty much do what You are looking for: 这里有一个使用curses模块的简单程序,几乎可以满足您的需求:

import curses
import time

stdscr = curses.initscr()

stdscr.addstr("line 1\n")
stdscr.addstr("line 2\n")
stdscr.refresh()
time.sleep(3)

stdscr.erase()
stdscr.addstr("edited line 1\n")
stdscr.addstr("edited line 2\n")
stdscr.refresh()
time.sleep(3)

curses.endwin()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM