我想找到一种使用Python在TextView GTK + 3上显示CSV文件的方法..
我已经测试了很多东西,但我无法使其正常工作
def on_button_program_list2_clicked(self, button, data=None):
self.window_list.show() # this is the window that contains the textview widget
self.text_view= self.builder.get_object("textview_list")
list_path=Data_Location+"/program-data/programs_to_install.csv"
list = csv.reader(open(list_path))
self.text_view.set_text(list)
如果可能,我想在行中显示文本,而不是python csv阅读器:
['string1'],['string2'],['string3']
但是作为
String1 String2 String3
非常感谢!
尝试更多东西..
def on_button_program_list2_clicked(self, button, data=None):
self.window_list.show()
self.textview1= self.builder.get_object("textview_list")
list_path=Data_Location+"/program-data/programs_to_install.csv"
lists = csv.reader(open(list_path))
lists = csv.reader(open(list_path))
text_buffer= Gtk.TextBuffer()
for item in lists:
output = item[0]+" "+item[1]+" "+item[2]+" "+item[3]
end_iter = text_buffer.get_end_iter()
text_buffer.insert(end_iter, output)
self.textview1 = Gtk.TextView(buffer=text_buffer)
但是我很难在textview小部件上显示它。此外,如果有更好的方式在行中显示项目而不是空格,那就太棒了!
答案 0 :(得分:0)
您检索列表,因此只需从中获取文本: (另)
lists = csv.reader(open(list_path))
output = ''
for alist in lists:
output += alist + '\n'
self.text_view.set_text(output)
对于一行中的输出,省略换行符号。 这有帮助吗?