Dane Brouwer
Dane Brouwer

Reputation: 2962

Tkinter text window writing with irremovable line space

I'm busy using tkinter in my python program, and I'm busy reading and then inserting into a text window, but there appears to be a line spacing between my input which shouldn't be there.

See following read to insert code:

def writer(self, Tk, textobject, n):
    for line in textobject:
            textwindow.insert(Tk.INSERT, line + "\n")
            self.sleeper(n)

See output:

TEXT LINE 1

TEXT LINE 2

EDIT: See what output should be:

TEXT LINE 1
TEXT LINE 2

Upvotes: 0

Views: 596

Answers (2)

Dane Brouwer
Dane Brouwer

Reputation: 2962

When using

textwindow.insert(Tk.INSERT, line + "\n")

There is no need to use

"\n"

As inserting a line creates its own new line already.
As such, I removed the "\n" and found that it worked perfectly.

Upvotes: 0

13smith_oliver
13smith_oliver

Reputation: 414

If you want the output to read TEXT LINE 1 TEXT LINE 2, remove the "\n".

Your code will look like:

def writer(self, Tk, textobject, n):
    for line in textobject:
            textwindow.insert(Tk.INSERT, line)
            self.sleeper(n)

Upvotes: 1

Related Questions