[英]Printing text from 2-D list python
I am making a GUI using pyqt4. 我正在使用pyqt4制作GUI。 In this application i am storing my result from database in a 2-d list and now i want to print this list in my GUI, but when i do so, every result is being printed on a new line, so how do i print 1 row in a line?
在此应用程序中,我将数据库中的结果存储在二维列表中,现在我想在我的GUI中打印此列表,但是当我这样做时,每个结果都将打印在新的一行上,因此如何打印1排成一行?
for row in to_d_col:
clm = ''
for col in row:
q=q+1
item = QtGui.QListWidgetItem("%i) %s"% (q,col))
I have tried to store the result in a string and then print it, it works fine by that way but the spaces between the words create a problem. 我试图将结果存储在字符串中,然后将其打印出来,那样可以正常工作,但是单词之间的空格会产生问题。
for row in to_d_col:
clm = ''
for col in row:
clm = clm +str(col)+"\t"
q=q+1
item = QtGui.QListWidgetItem("%i) %s"% (q,clm))
self.listWidget_2.addItem(item)
self.listWidget_2.addItem(item)
You should probably use a QtGui.QTableWidget instead of a listwidget, and fill it like so: 您可能应该使用QtGui.QTableWidget而不是listwidget,并像这样填充它:
widget = QtGui.QTableWidget(parent) # or get the widget some other way
for i, row in enumerate(to_d_col):
for j, value in enumerate(row):
ci = QtGui.QTableWidgetItem(value)
widget.setItem(i, j, ci)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.