LRS
LRS

Reputation: 45

How can I reprint 2D array or multiple outputs in the same line of (shell or window) with different output each time [Python 3.x]?

Lets say I have a 2D board where I have a games like Tetris had or Conveys Game of Life.

Is there is a way to reprint the whole 2D board over and over at the same place, be that shell or tkinter window (new to tkinter).

For 2D array output, I have a function print_2d_arr(arr) that simply loops through and prints each line one by one.

I've found multiple questions that either flush or use end="" approaches for single line replacement, or status bar creation, but really want to know if there is a simple and elegant command to do that, because whenever I tried to apply those techniques they kind of not applicable for my individually print_2d_arr function that outputs multiple lines simultaneously.

Thanks!

Upvotes: 1

Views: 44

Answers (1)

J_H
J_H

Reputation: 20425

The ANSI escape code ESC[0;0H will take you to top of screen.

But what you really want is the curses library.

Upvotes: 1

Related Questions