Skip to content

Instantly share code, notes, and snippets.

@adam-sas-on
Created May 28, 2020 15:17
Show Gist options
  • Select an option

  • Save adam-sas-on/3bd98b00f28fd78325cca080255e1bfb to your computer and use it in GitHub Desktop.

Select an option

Save adam-sas-on/3bd98b00f28fd78325cca080255e1bfb to your computer and use it in GitHub Desktop.
A simple example to use whole terminal screen in python
import curses
import random
def rand_range(width, height):
return (random.randint(0, width), random.randint(0, height) )
#
def run(stdscr):
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
run = True
stdscr.addstr(0, 4, "Random point on a board")
stdscr.addstr(1, 3, "Press any key for the next point")
stdscr.addstr(2, 3, "or ENTER for exit")
row_begin = 3
row = 3
col = 0
while run:
height,width = stdscr.getmaxyx()
width = width - 3
stdscr.move(row, col)
stdscr.addstr(row, col, " ")
row,col = rand_range(height-row_begin, width)
stdscr.addstr(row, col, "xxx")
c=stdscr.getch()
if c==curses.KEY_ENTER or c==10 or c==curses.KEY_EXIT:
run = False
#
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
if __name__ == '__main__':
curses.wrapper(run)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment