Box input text in Python || Python for begginers || basic code in python

Published: 31 January 2020
on channel: Sachin Meena
102
5

How to print a message box in python?

python string

I'm trying to print out a message within a created box in python, but instead of it printing straight down, it prints horizontally.


When you use list comprehension you get the output as list , as seen by your output, to see the new line character you need to print the result

And also you are using columns to multiply - which is only one for all strings. Change it to `row'

def border_msg(msg): row = len(msg) h = ''.join(['+'] + ['-' *row] + ['+']) result= h + '\n'"|"+msg+"|"'\n' + h print(result)

The above answers are good if you only want to print one line, however, they break down for multiple lines. If you want to print multiple lines you can use the following:


This will print a box around a multi-line string that is left-aligned with the specified padding values determining the positioning of the text in the box. Adjust accordingly.

If you would like to center the text, just use one padding value and interleave half of the spaces value from the spaces = h_len - len(m) line between the pipes.

Here's a mildly elaborated function for printing a message-box with optional title and indent which centers around the longest line:
"
#programmingknowledge #codewithharry #coder #pandas #trending #flask #Django #mail #bottel #begginers #jinja #dynamicprograming #specialcode


On this page of the site you can watch the video online Box input text in Python || Python for begginers || basic code in python with a duration of hours minute second in good quality, which was uploaded by the user Sachin Meena 31 January 2020, share the link with friends and acquaintances, this video has already been watched 102 times on youtube and it was liked by 5 viewers. Enjoy your viewing!