python钟表代码_Python实现模拟时钟代码推荐

本文介绍了如何使用Python结合PyQt4库创建一个模拟时钟,包括秒针显示,窗口透明度设置等功能。代码示例展示了小时、分钟和秒针的绘制,并提供了窗体透明和置顶的交互设计。
摘要由CSDN通过智能技术生成

import sys

from PyQt4 import QtGui, QtCore

from PyQt4.QtCore import Qt

from PyQt4.QtCore import QPoint

from PyQt4.QtCore import QTimer

from PyQt4.QtCore import QTime

from PyQt4.QtGui import QPainter

from PyQt4.QtGui import QColor

from PyQt4.QtGui import QPolygon

from PyQt4.QtCore import SIGNAL as signal

class Clock(QtGui.QWidget):

'''

classdocs

'''

def __init__(self):

'''

Constructor

'''

super(Clock, self).__init__()

self.hourColor=QColor(127, 0, 127);

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

self.secondColor=QColor(127, 127,0,120)

self.initUI()

self.timer = QTimer()

self.timer.timeout.connect(self.update)

self.timer.start(30)

self.show()

def handChange(self):

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

self.hand=(max(self.side/200,4), max(self.side/100,8), max(self.side/40,30))

self.hourHand=QPolygon([QPoint(self.hand[0],self.hand[1]),QPoint(-self.hand[0],self.hand[1]),QPoint(0,-self.hand[2])])

self.minuteHand=QPolygon([QPoint(self.hand[0],self.hand[1]),QPoint(-self.hand[0],self.hand[1]),QPoint(0,-self.hand[2]*2)])

self.secondHand=QPolygon([QPoint(self.hand[0],self.hand[1]),QPoint(-self.hand[0],self.hand[1]),QPoint(0,-self.hand[2]*3)])

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值