打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Python 初学桌面小时钟
进击的凉粉 2018-08-01 16:07:57

代码纯手打 留个纪念 共同进步

小时钟

#pip install PyQt5 安装PyQt5

from PyQt5.QtGui import *

from PyQt5.QtCore import *

from PyQt5.QtWidgets import QWidget, QDesktopWidget, QLCDNumber, QVBoxLayout, QApplication

import sys

import time

class MyTime(QWidget):

def __init__(self):

super().__init__()

self.initUI()

self.init_timer()

def init_timer(self):

self.timer = QTimer()

self.timer.setInterval(1000)

self.timer.start()

self.timer.timeout.connect(self.update_timer)

def update_timer(self):

self.lcd.display(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))

def initUI(self):

self.resize(250, 150)

self.setWindowTitle("桌面小时钟")

self.move_center()

self.main_pl = QPalette()

self.main_pl.setColor(QPalette.Background, Qt.darkGray)

self.setAutoFillBackground(True)

self.setPalette(self.main_pl)

self.lcd = QLCDNumber()

self.lcd.setDigitCount(20)

self.lcd.setMode(QLCDNumber.Dec)

self.lcd.setStyleSheet("border: 2px solid darkGray; color:#000000; background: silver;")

self.lcd.setSegmentStyle(QLCDNumber.Flat)

self.lcd.display(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))

self.main_layout = QVBoxLayout()

self.main_layout.addWidget(self.lcd)

self.main_layout.setAlignment(Qt.AlignCenter)

self.setLayout(self.main_layout)

self.show()

def move_center(self):

m_rect = self.frameGeometry()

w_center_top = QDesktopWidget().availableGeometry().center()

m_rect.moveCenter(w_center_top)

self.move(m_rect.topLeft())

if __name__ == '__main__':

app = QApplication(sys.argv)

m_time = MyTime()

sys.exit(app.exec_())

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
实战PyQt5: 094
使用python一起进入新年倒计时吧,可直接打包成exe应用!
Python如何开发桌面软件
PyQt5基础知识 超详细!!!(含代码)
PyQt4
eric6+pyqt5快速开发python GUI程序
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服