基于PYTHON和QT实现的一个时钟,PYTHONQT实现时钟,主要是模仿了qt自带的c
基于PYTHON和QT实现的一个时钟,PYTHONQT实现时钟,主要是模仿了qt自带的c
主要是模仿了qt自带的clock例子,然后 通过 python的语法 进行实现,
同时添加了秒针 的实现
用到的工具 有qt 4.8;python 2.7 ;pyqt
import sysfrom 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_()#该片段来自于http://byrx.net
相关内容
- python写的抽奖系统,python写抽奖系统,摇奖数据库文件如
- 一个简化的车站自动售票系统,简化车站售票系统,一个
- python解析binlog取得MySQL binlog的开始时间和结束时间,
- 多线程http压力测试,多线程压力测试,# Python ver
- 获取腾讯新闻正文和标题内容,腾讯新闻正文标题,#c
- python 3.3下结合tkinter做的猜数字程序,pythontkinter,3.3比大
- python Huffman树,pythonhuffman树,#!/usr/bin/p
- 多线程socket压力测试,socket压力测试,#!/user/bin/
- 通过动态代理生成基于gfwlist的动态代理脚本,,#!/usr/
- Learn Python By Practice — 正则表达式,pythonpractice,'''Crea
评论关闭