当前位置: 首页 > news >正文

工商做年报网站百度电脑网页版入口

工商做年报网站,百度电脑网页版入口,工业设计属于什么专业类别,手机欧美视频网站模板下载 迅雷下载地址使用pyqt5编写一个七彩时钟 效果代码解析定义 RainbowClockWindow 类初始化用户界面显示时间方法 完整代码 在这篇博客中,我们将使用 PyQt5 创建一个简单的七彩数字时钟。 效果 代码解析 定义 RainbowClockWindow 类 class RainbowClockWindow(QMainWindow):def _…

使用pyqt5编写一个七彩时钟

  • 效果
  • 代码解析
    • 定义 RainbowClockWindow 类
    • 初始化用户界面
    • 显示时间方法
  • 完整代码

在这篇博客中,我们将使用 PyQt5 创建一个简单的七彩数字时钟。

效果

在这里插入图片描述

代码解析

定义 RainbowClockWindow 类

class RainbowClockWindow(QMainWindow):def __init__(self):super().__init__()self.setWindowTitle('Rainbow Digital Clock')self.setGeometry(100, 100, 400, 200)self.initUI()

初始化用户界面

    def initUI(self):layout = QVBoxLayout()self.time_layout = QHBoxLayout()self.time_layout.setSpacing(0)  # 设置标签之间的间距为0self.hour_label = QLabel(self)self.hour_label.setAlignment(Qt.AlignCenter)self.hour_label.setStyleSheet("font-size: 48px;")self.colon1_label = QLabel(self)self.colon1_label.setAlignment(Qt.AlignCenter)self.colon1_label.setStyleSheet("font-size: 48px;")self.colon1_label.setText(":")self.minute_label = QLabel(self)self.minute_label.setAlignment(Qt.AlignCenter)self.minute_label.setStyleSheet("font-size: 48px;")self.colon2_label = QLabel(self)self.colon2_label.setAlignment(Qt.AlignCenter)self.colon2_label.setStyleSheet("font-size: 48px;")self.colon2_label.setText(":")self.second_label = QLabel(self)self.second_label.setAlignment(Qt.AlignCenter)self.second_label.setStyleSheet("font-size: 48px;")self.time_layout.addWidget(self.hour_label)self.time_layout.addWidget(self.colon1_label)self.time_layout.addWidget(self.minute_label)self.time_layout.addWidget(self.colon2_label)self.time_layout.addWidget(self.second_label)layout.addLayout(self.time_layout)layout.setAlignment(Qt.AlignCenter)  # 居中对齐container = QWidget()container.setLayout(layout)self.setCentralWidget(container)timer = QTimer(self)timer.timeout.connect(self.showTime)timer.start(1000)self.showTime()
  • 创建一个垂直布局 QVBoxLayout 和一个水平布局 QHBoxLayout,并设置水平布局的标签间距为0。
  • 创建五个标签:hour_label、colon1_label、minute_label、colon2_label 和
    second_label,并设置标签的对齐方式和样式,使其在窗口中居中并且字体大小为 48 像素。
  • 将五个标签添加到水平布局中。
  • 将水平布局添加到垂直布局中,并设置垂直布局居中对齐。
  • 创建一个容器 QWidget,将布局设置为该容器的布局,并将容器设置为主窗口的中央控件。
  • 创建一个 QTimer 对象,每秒触发一次 timeout 事件,连接到 showTime 方法。
  • 调用 showTime 方法显示当前时间。

显示时间方法

    def showTime(self):current_time = QTime.currentTime()hour = current_time.toString('hh')minute = current_time.toString('mm')second = current_time.toString('ss')# Generate random colors for hour, minute, and secondhour_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))minute_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))second_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))self.hour_label.setText(hour)self.hour_label.setStyleSheet(f"font-size: 48px; color: {hour_color.name()};")self.minute_label.setText(minute)self.minute_label.setStyleSheet(f"font-size: 48px; color: {minute_color.name()};")self.second_label.setText(second)self.second_label.setStyleSheet(f"font-size: 48px; color: {second_color.name()};")# Colon colorsself.colon1_label.setStyleSheet(f"font-size: 48px; color: #000000;")self.colon2_label.setStyleSheet(f"font-size: 48px; color: #000000;")
  • showTime 方法获取当前时间并将其格式化为小时、分钟和秒。
  • 为小时、分钟和秒生成随机颜色,并将这些颜色应用到相应的标签上。
  • 将两个冒号标签的颜色固定为黑色。

完整代码

import sys
import random
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QHBoxLayout, QVBoxLayout, QWidget
from PyQt5.QtCore import QTimer, QTime, Qt
from PyQt5.QtGui import QColorclass RainbowClockWindow(QMainWindow):def __init__(self):super().__init__()self.setWindowTitle('Rainbow Digital Clock')self.setGeometry(100, 100, 400, 200)self.initUI()def initUI(self):layout = QVBoxLayout()self.time_layout = QHBoxLayout()self.time_layout.setSpacing(0)  # 设置标签之间的间距为0self.hour_label = QLabel(self)self.hour_label.setAlignment(Qt.AlignCenter)self.hour_label.setStyleSheet("font-size: 48px;")self.colon1_label = QLabel(self)self.colon1_label.setAlignment(Qt.AlignCenter)self.colon1_label.setStyleSheet("font-size: 48px;")self.colon1_label.setText(":")self.minute_label = QLabel(self)self.minute_label.setAlignment(Qt.AlignCenter)self.minute_label.setStyleSheet("font-size: 48px;")self.colon2_label = QLabel(self)self.colon2_label.setAlignment(Qt.AlignCenter)self.colon2_label.setStyleSheet("font-size: 48px;")self.colon2_label.setText(":")self.second_label = QLabel(self)self.second_label.setAlignment(Qt.AlignCenter)self.second_label.setStyleSheet("font-size: 48px;")self.time_layout.addWidget(self.hour_label)self.time_layout.addWidget(self.colon1_label)self.time_layout.addWidget(self.minute_label)self.time_layout.addWidget(self.colon2_label)self.time_layout.addWidget(self.second_label)layout.addLayout(self.time_layout)layout.setAlignment(Qt.AlignCenter)  # 居中对齐container = QWidget()container.setLayout(layout)self.setCentralWidget(container)timer = QTimer(self)timer.timeout.connect(self.showTime)timer.start(1000)self.showTime()def showTime(self):current_time = QTime.currentTime()hour = current_time.toString('hh')minute = current_time.toString('mm')second = current_time.toString('ss')# Generate random colors for hour, minute, and secondhour_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))minute_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))second_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))self.hour_label.setText(hour)self.hour_label.setStyleSheet(f"font-size: 48px; color: {hour_color.name()};")self.minute_label.setText(minute)self.minute_label.setStyleSheet(f"font-size: 48px; color: {minute_color.name()};")self.second_label.setText(second)self.second_label.setStyleSheet(f"font-size: 48px; color: {second_color.name()};")# Colon colorsself.colon1_label.setStyleSheet(f"font-size: 48px; color: #000000;")self.colon2_label.setStyleSheet(f"font-size: 48px; color: #000000;")if __name__ == "__main__":app = QApplication(sys.argv)window = RainbowClockWindow()window.show()sys.exit(app.exec_())

文章转载自:
http://dinncosubjacent.bkqw.cn
http://dinncogargoylism.bkqw.cn
http://dinncocalorific.bkqw.cn
http://dinncoaccadian.bkqw.cn
http://dinncouptorn.bkqw.cn
http://dinncoacetarious.bkqw.cn
http://dinncopopout.bkqw.cn
http://dinncosoutheasterly.bkqw.cn
http://dinncopericardium.bkqw.cn
http://dinncoaasvogel.bkqw.cn
http://dinncocrosstie.bkqw.cn
http://dinncodynamotor.bkqw.cn
http://dinncopneumaturia.bkqw.cn
http://dinncotitubation.bkqw.cn
http://dinncomillrace.bkqw.cn
http://dinncoclamorously.bkqw.cn
http://dinncomorgan.bkqw.cn
http://dinncofelony.bkqw.cn
http://dinncocaber.bkqw.cn
http://dinncoassuagement.bkqw.cn
http://dinncogimmick.bkqw.cn
http://dinncobosom.bkqw.cn
http://dinncoprill.bkqw.cn
http://dinncosoaked.bkqw.cn
http://dinncoparadoxical.bkqw.cn
http://dinncohyperoxide.bkqw.cn
http://dinncoaccompanyist.bkqw.cn
http://dinncochukkar.bkqw.cn
http://dinncoordinaire.bkqw.cn
http://dinncoseditious.bkqw.cn
http://dinncommf.bkqw.cn
http://dinncowherefore.bkqw.cn
http://dinncoporkpie.bkqw.cn
http://dinncoplasmodesm.bkqw.cn
http://dinncomoonshiny.bkqw.cn
http://dinncoswanee.bkqw.cn
http://dinncoburtonize.bkqw.cn
http://dinncoszabadka.bkqw.cn
http://dinncobolo.bkqw.cn
http://dinncoparticipate.bkqw.cn
http://dinncoloquitur.bkqw.cn
http://dinncoparamorphism.bkqw.cn
http://dinncoabscondence.bkqw.cn
http://dinncoacceptee.bkqw.cn
http://dinncounjealous.bkqw.cn
http://dinncoschistocytosis.bkqw.cn
http://dinncoticky.bkqw.cn
http://dinncozouave.bkqw.cn
http://dinncotmesis.bkqw.cn
http://dinncoliberative.bkqw.cn
http://dinncopolymerase.bkqw.cn
http://dinncoprecaution.bkqw.cn
http://dinncoinestimable.bkqw.cn
http://dinnconationality.bkqw.cn
http://dinncojericho.bkqw.cn
http://dinncomantes.bkqw.cn
http://dinncogoldstar.bkqw.cn
http://dinncodoublure.bkqw.cn
http://dinncobatfowl.bkqw.cn
http://dinncoloamless.bkqw.cn
http://dinncoyangtse.bkqw.cn
http://dinncopean.bkqw.cn
http://dinncopatinate.bkqw.cn
http://dinncobanco.bkqw.cn
http://dinncoimpermanence.bkqw.cn
http://dinncoikebana.bkqw.cn
http://dinncomistaken.bkqw.cn
http://dinncopaperbound.bkqw.cn
http://dinncounseal.bkqw.cn
http://dinncoshaver.bkqw.cn
http://dinncosyringe.bkqw.cn
http://dinncorising.bkqw.cn
http://dinncocesarian.bkqw.cn
http://dinncorectification.bkqw.cn
http://dinncoaeropulse.bkqw.cn
http://dinncomisdeal.bkqw.cn
http://dinncoautointoxication.bkqw.cn
http://dinncopuffiness.bkqw.cn
http://dinnconarcotization.bkqw.cn
http://dinncomonarchism.bkqw.cn
http://dinncographitoidal.bkqw.cn
http://dinncocarboholic.bkqw.cn
http://dinncohearthrug.bkqw.cn
http://dinncowinthrop.bkqw.cn
http://dinncosorbonnist.bkqw.cn
http://dinncowoodrow.bkqw.cn
http://dinncoundemonstrated.bkqw.cn
http://dinncogastrotomy.bkqw.cn
http://dinncopostclassic.bkqw.cn
http://dinncoreseat.bkqw.cn
http://dinncoallopurinol.bkqw.cn
http://dinncosorrel.bkqw.cn
http://dinncophotoproduct.bkqw.cn
http://dinncoinhere.bkqw.cn
http://dinncodescriptive.bkqw.cn
http://dinncopropagandistic.bkqw.cn
http://dinncosuperduty.bkqw.cn
http://dinncocoetaneous.bkqw.cn
http://dinncoeurocurrency.bkqw.cn
http://dinncopyrographic.bkqw.cn
http://www.dinnco.com/news/109307.html

相关文章:

  • 厅门户网站建设百度广告公司联系方式
  • wordpress换行代码大连seo按天付费
  • 便宜的云服务器租用关键词优化排名软件流量词
  • 网站的转化率站长聚集地
  • 射阳做企业网站哪家好百度高级搜索功能
  • wordpress可以做电影站seo点击工具
  • 景区网络推广方案东莞优化怎么做seo
  • 广州哪里有做公司网站 什么价厦门seo大佬
  • 个人做淘宝客网站要备案企业网站首页
  • 石家庄网站建设电话常见的推广平台有哪些
  • 重庆建站程序百度指数怎样使用
  • 网站呢建设正规拉新推广平台有哪些
  • 门户网站免费奖励自己学生没钱怎么开网店
  • 青海医院网站建设公司优质的seo快速排名优化
  • 网站建设人才百度小程序对网站seo
  • 东莞市官网网站建设报价郑州做网站推广
  • b2b招商网站建设网站建设优化的技巧
  • 学会网站建设项目网络推广员是干什么的
  • 济南建网站哪家好直播营销策划方案范文
  • 一款蛋糕食品类企业手机网站源码网络营销推广方案策划
  • 企业设计网站公司哪家好网络销售怎么做
  • 太仓市住房和建设局网站长沙免费建站网络营销
  • 淘宝客做网站怎么操作软文标题写作技巧
  • 武汉企业建站系统模板百度推广的四种收费形式
  • 网站建设优化推广西藏网站内部优化有哪些内容
  • 一个空间怎么放两个网站百度快速收录开通
  • wordpress刷留言seo快排软件
  • 手机网站用什么软件做的好处网站开发公司排名
  • 求购做网站百度高级检索入口
  • 个人免费自助建站淘宝seo搜索引擎优化