标签:style blog http color os io for 2014
# -*- coding: utf-8 -*-
# python:2.x
__author__ = ‘Administrator‘
from PyQt4.QtGui import *
from PyQt4.Qt import *
from PyQt4.QtCore import *
lista = [‘aa‘, ‘ab‘, ‘ac‘]
listb = [‘ba‘, ‘bb‘, ‘bc‘]
listc = [‘ca‘, ‘cb‘, ‘cc‘]
mystruct = {‘A‘:lista, ‘B‘:listb, ‘C‘:listc}
import sys
class Example(QTableWidget):
def __init__(self,t,*args):
super(Example, self).__init__(*args)
self.tab=t
self.datas()
def datas(self):
n=0
for k in self.tab:
m=0
for items in self.tab[k]:
newitem=QTableWidgetItem(items)
if k ==‘A‘:
newitem.setBackground(QColor(100,100,150))
elif k==‘B‘:
newitem.setBackground(QColor(100,150,100))
else:
newitem.setBackground(QColor(150,100,100))
self.setItem(m,n,newitem)
m+=1
n+=1
app =QApplication(sys.argv)
#QApplication.setQuitOnLastWindowClosed(False)退出在最后窗口关闭点击
x = Example(mystruct,3,3)
x.show()
sys.exit(app.exec_())
如图:
pyqt QTableWidget例子学习(重点),布布扣,bubuko.com
标签:style blog http color os io for 2014
原文地址:http://www.cnblogs.com/mhxy13867806343/p/3887529.html