LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 841|回复: 0

SIGNAL+SLOT(rubbish)

[复制链接]
发表于 2006-9-22 15:07:03 | 显示全部楼层 |阅读模式
[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]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表