Hi everyone,

I have a problem to insert text into a text widget in Tkinter.
I want to be able that each time some text is inserted (by means of an action -not directly by the user-) that text is displayed into a new line.
However I can't figure out how to do this because everything I've tried showed me the same result: the new text is appended to the last character of the old text.
I've also tried to use the expression formatting, as shown in the following code excerpt, without success.
Can someone help me with this?

i = "%s: %s" % (self.PSprod, self.PSv)  
self.InfoPoint.insert("%s lineend" % INSERT, i)

Thanks a lot,


Recommended Answers

All 2 Replies

Will something like this do?

import Tkinter as tk

def set_text_newline(s):
    """start text s on a new line"""
    text1.insert(tk.INSERT, '\n' + s)

root = tk.Tk()
# width=width characters, height=lines of text
text1 = tk.Text(root, width=50, height=12, bg='yellow')

set_text_newline("line one")
set_text_newline("line two")
set_text_newline("line three")


Thanks a lot!
It now works perfectly like this

self.InfoPoint.insert (INSERT, i)
self.InfoPoint.insert(END, "\n")

Again, thank you so much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.