7

Using Python, I would like to print a line that will appear on the last visible line on the console the script is being ran from. For example, something like this:

enter image description here

Would this be able to be done?

Markum
  • 3,919
  • 8
  • 26
  • 30

2 Answers2

2

The easiest way is to use effbot.org's Console module:

import Console

c = Console.getconsole()
c.text(0, -1, 'And this is the string at the bottom of the console')

By specifying -1 for the second (line) argument you are addressing the last line of the console.

Because the Console module only works on Windows, to get this to work on UNIX terminals as well, you should take a look at the wcurses library, which provides a partial curses implementation that'll work on Windows. You'd drive it the same as the stdlib curses module; use the first on Windows, the latter on UNIX.

APerson
  • 8,140
  • 8
  • 35
  • 49
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 1
    I don't think effbot has a download for their module for Python 2.7, I tried downloading the 2.6 version but it would not let me install. – Markum May 27 '12 at 13:34
  • He does provide the source code, perhaps you can compile it yourself? I know, Python extensions on Windows are a pain. The wcurses module also requires compilation. – Martijn Pieters May 27 '12 at 13:39
  • Can the text written at the bottom of the console edited? // The link seems dead: it says `effbot.org is taking a break. We’ll be back, in some form or another.` – alper May 21 '22 at 11:27
  • 1
    @alper I’ll try and update the answer soon. In the meantime, know that effbot’s project was Python 2 only. You could take a look at https://pypi.org/project/UniCurses instead. I’ll probably use that to update this answer with. – Martijn Pieters May 22 '22 at 20:00
  • @MartijnPieters seems like https://pypi.org/project/UniCurses/ is abondened . – alper Jul 29 '22 at 16:32
  • @alper: https://github.com/unicurses/unicurses / https://pypi.org/project/Uni-Curses/ appears to have picked up the torch. – Martijn Pieters Aug 13 '22 at 16:01
  • @MartijnPieters I have look into `unicurses` but was unable to find related example regarding to print text at the bottom of terminal – alper Apr 29 '23 at 07:22
  • 1
    @alper: the [`addstr()` method](https://docs.python.org/3/library/curses.html#curses.window.addstr) lets you position text within a curses window. See the [unicurses `test_windows.py` demo](https://github.com/unicurses/unicurses/blob/master/demos/test_windows.py) for how to get a window and its size; just create one for the maximum column and line count, without a box. – Martijn Pieters Jun 09 '23 at 10:01
  • I was more likely to achieve output like tmux does (like it shows date at right bottom corner) where print a text at the bottom of the console/terminal – alper Jun 09 '23 at 11:27
1

For a Windows terminal try the console module For unix the curses module would do.

ditkin
  • 6,774
  • 1
  • 35
  • 37