How to add tab or spaces in front of multiple lines How to add tab or spaces in front of multiple lines tkinter tkinter

How to add tab or spaces in front of multiple lines


As I now understand your question (based on your comment below), here is how it could be done with the help of the textwrap module.

Note this doesn't put tab characters in front of the lines, instead it puts a prefix string composed of space characters so they will line up. If you really want tab characters, set prefix = '\t' instead of what is shown.

import textwrap# button for text inputdef insert():    note = entry_note.get() + ' : '    text = note + entry_defs.get('1.0', 'end-1c')    textlines = text.splitlines(True)    prefix = ' ' * len(note)    formatted = textlines[0] + textwrap.indent(''.join(textlines[1:]), prefix)    print(formatted)    # f = open('MyPyDict.txt', 'a', encoding='utf-8')    # f.write(formatted + '\n')