不全屏刷新,只刷新部分屏幕
你可以看看这个 Python 的 mwe (windows下)
[Python] 纯文本查看 复制代码 from time import sleep
from queue import Queue
from os import system
from _thread import start_new_thread
import ctypes
class COORD(ctypes.Structure):
_fields_ = [("X", ctypes.c_short), ("Y", ctypes.c_short)]
def __init__(self, x, y):
self.X = x
self.Y = y
def setpos(pos) -> None:
ctypes.windll.kernel32.SetConsoleCursorPosition(
ctypes.windll.kernel32.GetStdHandle(-11), COORD(int(pos[1]), pos[0])
)
tasks = Queue()
def queued_print(s:str, interval:float=0.02, init_pos=[0, 0]) -> None:
y, x = init_pos
dy, dx = 0, 0
for ch in s:
if ch == "\n":
dy += 1
dx = 0
else:
tasks.put({'s': ch, 'pos': [y + dy, x + dx]})
dx += 1
sleep(interval)
def printer():
global board
while True:
data = tasks.get()
setpos(data['pos'])
print(data['s'], end='', flush=True)
system("cls")
start_new_thread(printer, ())
start_new_thread(queued_print, ("Threaded print 1", 0.02, [5, 0]))
start_new_thread(queued_print, ("Threaded print 2", 0.02, [1, 0]))
sleep(0.5)
queued_print("Queued print", 0.02, [5, 0])
sleep(3) |