所以我有一個串列,看起來像
的串列[('9/13/2021', 2.0, '7:15', '希爾') 。
('9/14/2021', 8.0, '6:0', '節奏感')。
('9/14/2021', 4.0, '6:0', 'Tempo') ]
我知道如何列印出來才好看,但我想讓它在Gtk中顯示出來,它列印到顯示幕中的樣子是這樣的:
我正在尋找一種方法,以使其列印出擺脫大括號、逗號和引號,但仍在同一行中。
我的列印方式是這樣的:
我的列印方式是這樣的。
items = self.read_from_db()
# 列舉了所提取的專案,并將它們添加到中。
# 顯示的提醒事項串列。
for item in items:
self.listbox_2.add(ListBoxRowWithData(item))
其中read_from_db()回傳一個串列中的串列。有什么想法嗎?
這里是ListBoxRowWithData類:
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', '希爾'), ('9/14/2021', 8. 0, '6:0', 'Tempo'/span>), ('9/14/2021', 4. 0, '6:0', 'Tempo') ]
uj5u.com熱心網友回復:
目前,標簽文本是一個串列的字串表示。要把串列連接成一個字串,你可以使用字串的.join。
self.listbox_2.add(ListBoxRowWithData(" "/span>. join([str(x) for x in item] ))
.join只有當串列中的所有專案都是字串時才會起作用,所以[str(x) for x in item]串列理解將把每個串列項轉換成字串。然后,這些專案被用空格連接起來,但是如果你愿意,你可以使用不同的連接字串。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/308538.html
標籤:
上一篇:HTML5 新增內容和 API
