Here is my problem, I can't quite find the answer elsewhere. I want to show some text in a Gtk textview (python3), with a new line after each piece of text. When I use "\n", it shows "\n" rather than actually adding in a new line. Is there a way that I can fix this?
This should be a reproducible version of my problem and then my output... (ps. I'm not an experienced programmer)
from gi.repository import Gtk
records = ()
tv = Gtk.TextView()
records += ("a", "\n", "b", "\n", "c", "\n")
tb = tv.get_buffer()
sw = Gtk.ScrolledWindow()
w = Gtk.Window()
('a','\n','b', '\n', 'c')
I have been shown a way to solve this problem by using
%s string formatting. Here is a sample of the code I was actually working with:
tv = Gtk.TextView() for record in records: records_str += "Title: %s \nAuthors: %s \nSource: %s\n\n" %(record.get("TI"), ", ".join(record.get("AU")), record.get("SO")) tb = tv.get_buffer() tb.set_text("".join(records_str))
This prints "Title", "Author" and "Source" on separate lines.