-1

I have seen numerous questions similar to this but yet to see one directly related. Hopefully I can add to the information that has been floating around over the years.

Lets say I have my little CLI app.py and I want to "fancy" it up, for example.

#########################################################################
                         Welcome to my App
#########################################################################


someInput> 

Let's see how many ways there are to skin this cat.

  • maybe see https://stackoverflow.com/questions/566746/how-to-get-linux-console-window-width-in-python – njzk2 Sep 15 '19 at 22:35
  • You are expected to perform basic research and make an effort. Please show the relevant code and state where you are having problems. Also see [Why is the “how to move the turtle in logo” question closed?](https://meta.stackexchange.com/q/158289) and [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – jww Sep 16 '19 at 00:25
  • I'm not asking a question but clearing up one. I see many questions that are asked not knowing what they are truly asking. – Furikuri Yugi Sep 16 '19 at 17:52

2 Answers2

0

I usually add some ASCII art as a 'splash screen' for console apps. For example, you may use this site to generate your ASCII. Then store it into a text file and print from your code:

def print_splash():
    with open('splash', 'r') as f:
        print(f.read())
s0mbre
  • 361
  • 2
  • 14
0

The best way I can think of to accomplish this is in the following way. Just think about it: we don't really care about the DPI or the resolution; we just want to adjust our output to our terminal window size. Precisely, the columns or width.

#!/usr/bin/python

import os

size = int(os.popen('tput cols').read().strip())
print('#' * size)
print('Welcome to my App').center(size))
print('#' * size,'\n\n')
i = input('What's your name? ')

We are using popen() to run a shell command 'tput' to get the columns('cols') of our window, getting the answer with read(), striping the trailing new line with strip(), converting it to an integer and then saving it to the variable size.

Next we are printing pound signs(#) based on the number of columns (size)

Next we are using center() to align out text to the middle of the window(size).

The rest I think is self explanatory we just added 2 new lines to the end of our bottom pound signs(#)

I hope this clears some things up for anyone that hasn't figured out how to ask the right question.

Links: popen(), read(), strip(), center(), tput