How to minimize the space inside rows? #3251
-
Hi everyone, Here is a brief summary of my issue. I am trying to create Conway's game of life and my goal is to display the board in the terminal using Rich (maybe not the most efficient way, but it teaches me how to use Rich). The cells are filled with "■" when they are alive, and "□" when they are dead, so they are all the same width and the board should be a square. As you can see in the following screenshot, I managed to minimize the space between each column, but there is still space between each row: Here is the code that does it : def update_table(board: Board) -> Table:
table = Table(title="Game of Life", show_header=False, show_footer=False, show_edge=False, box=None)
table.padding = (0, 0)
table.pad_edge = False
columns = board.shape[1]
for column in range(columns):
table.add_column(no_wrap=True)
for row in board:
formatted_row = ["■" if element else "□" for element in row]
table.add_row(*formatted_row)
return table I have tried many different combinations of options for Table(), but none let's me do what I want. So does anyone know how I could remove the space between each row entirely ? Here is the repo if you want to check out the full code (it's only two files): Yoyoda75/game_of_life Thanks in advance ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Unicode has a full block character (u2588) which hopefully will help explain the gaps between your rows. Try running the code below: BLACK_SQUARE = "■" # u25a0
FULL_BLOCK = "█" # u2588
for _ in range(3):
print(BLACK_SQUARE, FULL_BLOCK) |
Beta Was this translation helpful? Give feedback.
Unicode has a full block character (u2588) which hopefully will help explain the gaps between your rows. Try running the code below: