So I have a list in a list that looks like
[('9/13/2021', 2.0, '7:15', 'Hill'),
('9/14/2021', 8.0, '6:0', 'Tempo'),
('9/14/2021', 4.0, '6:0', 'Tempo')]
and I understand how to print it out to look good but I am trying to get it to display in Gtk and it prints into the display looking like this:
I am looking for a way to get it to print out where it gets rid of the brackets, commas and quotation marks but is still within the same line.
The way I am printing to the is like this:
items = self.read_from_db()
# lists through the items pulled and adds them to the
# list of reminders displayed
for item in items:
self.listbox_2.add(ListBoxRowWithData(item))
Where read_from_db()
returns the lists within a list. Any thoughts?
Here is the ListBoxRowWithData class:
class ListBoxRowWithData(Gtk.ListBoxRow):
def __init__(self, data):
super().__init__()
self.data = data
self.add(Gtk.Label(label=data))
Items output:
[('9/13/2021', 2.0, '7:15', 'Hill'), ('9/14/2021', 8.0, '6:0', 'Tempo'), ('9/14/2021', 4.0, '6:0', 'Tempo')]
CodePudding user response:
Currently the label text is a string representation of the list. To join the list into a string, you can use the .join
of a string.
self.listbox_2.add(ListBoxRowWithData(" ".join([str(x) for x in item])))
.join
will only work if all the items in the list are strings, so the [str(x) for x in item]
list comprehension will convert every list item to a string. The items are then joined with a space but you can use a different joining string if you'd like.