我试图在其中显示移动个体的网格。目前我使用“清除屏幕”然后显示网格。这很麻烦,因为屏幕每次都“闪烁”。
在C和VB.NET中,有一些方法可以强制托架返回控制台的开头并覆盖内容。这消除了闪烁。
Python可以这样做吗?我已经用Google搜索了,我找到了Curses,但那只是Unix(我将主要在Windows中工作)。
当前网格代码(超级基础):
#Clear() is a OS indepedent method of clearing the screen defined in code above, in windows its just os.system('cls')
clear()
x=0
y=0
tiles=""
tile=""
# Generate grid
while(y<max_y):
while(x<max_x):
tile = tileGen(x,y)
tiles += str(tile)
x+=1
tiles += "\n"
y+=1
x=0
print(tiles)
答案 0 :(得分:3)
也许这会有所帮助:ANSI Escape Sequences
Home命令为'\x1b[0;0H'
。
答案 1 :(得分:0)
对于它的价值,一个python包确实存在包装PDCurses,一个与Windows兼容的curses库。包UniCurses
为PDCurses(在windows下)或python的本地curses
模块提供了统一的接口,因此可以用来编写跨平台的curses应用程序。可能Mike Desimone的答案足以满足您的需求。