使用 PyQt4:
import sys
from PyQt4 import QtCore, QtGui
def F(n, m):
return n + m
class MainWindow(QtGui.QWidget):
# http://stackoverflow.com/a/11458784/190597 (reclosedev)
def __init__(self, parent=None):
self.rows = range(50)
self.cols = range(100)
super(MainWindow, self).__init__(parent)
self.table_widget = QtGui.QTableWidget()
layout = QtGui.QVBoxLayout()
layout.addWidget(self.table_widget)
self.setLayout(layout)
self.populate()
def populate(self):
self.table_widget.setRowCount(len(self.rows))
self.table_widget.setColumnCount(len(self.cols))
self.table_widget.setHorizontalHeaderLabels(map(str, self.cols))
for i, n in enumerate(self.rows):
for j, m in enumerate(self.cols):
value = QtGui.QTableWidgetItem(str(F(n, m)))
self.table_widget.setItem(i, j, value)
self.table_widget.item(5,2).setBackgroundColor(QtGui.QColor(0,255,255))
self.table_widget.item(5,2).setTextColor(QtGui.QColor("red"))
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
wnd = MainWindow()
wnd.resize(640, 480)
wnd.show()
sys.exit(app.exec_())