python数码时钟代码_[代码全屏查看]-基于PYTHON和QT实现的一个时钟

[1].[代码] [Python]代码

import sys

from PyQt4.QtCore import *

from PyQt4.QtGui import *

class clock (QWidget):

def __init__(self):

QWidget.__init__(self,windowTitle="python clock")

timer = QTimer(self)

self.connect(timer, SIGNAL("timeout()"),self,SLOT("update()"))

timer.start(1000)

self.resize(200,200)

def paintEvent(self,e):

hourColorHand = QPolygon([QPoint(7,8),QPoint(-7,8),QPoint(0,-30)])

minuteColorHand = QPolygon([QPoint(7,8),QPoint(-7,8),QPoint(0,-70)])

secondColorHand = QPolygon([QPoint(3,8),QPoint(-3,8),QPoint(0,-90)])

hourColor = QColor(127,0,127)

minuteColor = QColor(0,127,127,191)

secondColor = QColor(0,100,100,100)

painter = QPainter(self);

side = min(self.width(),self.height())

atime =QTime.currentTime()

painter.setRenderHint(QPainter.Antialiasing)

painter.translate(self.width()/2,self.height()/2)

painter.scale(side/200,side/200)

painter.setPen(Qt.NoPen)

painter.setBrush(hourColor)

painter.save()

painter.rotate(30.0*(atime.hour() + atime.minute()/60.0))

painter.drawConvexPolygon(hourColorHand)

painter.restore()

painter.setPen(hourColor)

for i in range(0,12):

painter.drawLine(88,0,96,0)

painter.rotate(30.0)

painter.setPen(Qt.NoPen)

painter.setBrush(minuteColor)

painter.save()

painter.rotate(6.0*(atime.minute()+atime.second()/60.0))

painter.drawConvexPolygon(minuteColorHand)

painter.restore()

painter.setPen(minuteColor)

for i in range(0,60) :

if (i%5)!=0 :

painter.drawLine(92,0,96,0)

painter.rotate(6.0)

painter.setPen(Qt.NoPen)

painter.setBrush(secondColor)

painter.save()

painter.rotate(6.0 * atime.second())

painter.drawConvexPolygon(secondColorHand)

painter.restore()

if __name__ == "__main__" :

q = QApplication(sys.argv)

s = clock()

s.show()

q.exec_()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值