|
- #!/usr/bin/python
- #Filename:<what's your name?>
- from PyQt4 import QtCore,QtGui
- import sys,random
- class Main(QtGui.QWidget):
- def __init__(self):
- QtGui.QWidget.__init__(self)
-
- self.frame = QtGui.QFrame(self)
- self.frame.setGeometry(QtCore.QRect(0,0,150,150))
-
- self.labelA = QtGui.QLabel('A',self.frame)
- self.labelB = QtGui.QLabel('B',self.frame)
- self.labelO = QtGui.QLabel('+',self.frame)
- self.labelE = QtGui.QLabel('||',self.frame)
- self.labelR = QtGui.QLabel('R',self.frame)
-
- self.labelA.setGeometry(QtCore.QRect(65,40,25,10))
- self.labelO.setGeometry(QtCore.QRect(65,55,25,10))
- self.labelB.setGeometry(QtCore.QRect(65,70,25,10))
- self.labelE.setGeometry(QtCore.QRect(65,85,25,10))
- self.labelR.setGeometry(QtCore.QRect(65,105,25,10))
-
- self.timer = QtCore.QTimer(self)
- self.connect(self.timer,QtCore.SIGNAL("timeout()"),self,QtCore.SLOT("update()"))
-
- self.resize(150,150)
- self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
- maskRegion = QtGui.QRegion(25,25,100,100,QtGui.QRegion.Ellipse)
- self.setMask(maskRegion)
-
- def paintEvent(self,event):
- a = random.randint(0,100)
- b = random.randint(0,100)
- self.labelA.setNum(a)
- self.labelB.setNum(b)
- self.labelR.setNum(a+b)
-
- def mousePressEvent(self, event):
- if event.buttons() == QtCore.Qt.LeftButton:
- self.timer.start(250)
- else:
- self.timer.stop()
- ########################
- # main routine #
- ########################
- if __name__ == '__main__':
- app = QtGui.QApplication(sys.argv)
-
- run = Main()
- run.show()
-
- app.exec_()
复制代码 |
|