|
[php]
#!/usr/bin/python
#Filename:hello6.py
from PyQt4 import QtGui,QtCore
import sys
class Button(QtGui.QPushButton):
def __init__(self,text,colour):
QtGui.QPushButton.__init__(self)
self.setText(str(text))
newPalette = self.palette()
newPalette.setColor(QtGui.QPalette.Button, colour)
self.setPalette(newPalette)
class Compute(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.button = list(range(10))
grid = QtGui.QGridLayout()
for row in range(3):
for col in range(3):
now = 3*row+col+1
self.button[now] = Button(now,QtGui.QColor(125,255,125))
grid.addWidget(self.button[now],row,col)
self.button[0] = Button(0,QtGui.QColor(125,255,125))
grid.addWidget(self.button[0],3,0)
for i in range(10):
self.connect(self.button,QtCore.SIGNAL("clicked()"),self.func)
self.setLayout(grid)
def func(self):
button = self.sender()
value = button.text().toInt()
print '\t',value[0],'\b'*4,
sys.stdout.flush()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
run = Compute()
run.show()
app.exec_()
[/php] |
|