当前位置: 首页 > 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://incult.gtqx.cn
http://haloid.gtqx.cn
http://eriophyllous.gtqx.cn
http://execratory.gtqx.cn
http://blagueur.gtqx.cn
http://agley.gtqx.cn
http://lindesnes.gtqx.cn
http://pusley.gtqx.cn
http://maldevelopment.gtqx.cn
http://kolyma.gtqx.cn
http://millier.gtqx.cn
http://benzoyl.gtqx.cn
http://swank.gtqx.cn
http://tigrinya.gtqx.cn
http://fennec.gtqx.cn
http://metheglin.gtqx.cn
http://hypercorrect.gtqx.cn
http://metempiricism.gtqx.cn
http://leif.gtqx.cn
http://wri.gtqx.cn
http://prolific.gtqx.cn
http://narial.gtqx.cn
http://santero.gtqx.cn
http://manwise.gtqx.cn
http://misdoing.gtqx.cn
http://kilolitre.gtqx.cn
http://caleche.gtqx.cn
http://philhellenic.gtqx.cn
http://adultoid.gtqx.cn
http://woodstock.gtqx.cn
http://hippology.gtqx.cn
http://weaponization.gtqx.cn
http://propyl.gtqx.cn
http://tallit.gtqx.cn
http://clairvoyance.gtqx.cn
http://realisation.gtqx.cn
http://printmaking.gtqx.cn
http://cultus.gtqx.cn
http://wrist.gtqx.cn
http://prehormone.gtqx.cn
http://thieve.gtqx.cn
http://molybdite.gtqx.cn
http://merman.gtqx.cn
http://antithrombotic.gtqx.cn
http://glycolytic.gtqx.cn
http://sagaman.gtqx.cn
http://fabulous.gtqx.cn
http://fossil.gtqx.cn
http://masseter.gtqx.cn
http://gift.gtqx.cn
http://bicolor.gtqx.cn
http://sharebone.gtqx.cn
http://davy.gtqx.cn
http://ebracteate.gtqx.cn
http://sphygmus.gtqx.cn
http://televisual.gtqx.cn
http://demented.gtqx.cn
http://whirlicote.gtqx.cn
http://obcompressed.gtqx.cn
http://linden.gtqx.cn
http://shopwindow.gtqx.cn
http://breakthrough.gtqx.cn
http://chylomicron.gtqx.cn
http://tuneless.gtqx.cn
http://hazard.gtqx.cn
http://ldap.gtqx.cn
http://periphrase.gtqx.cn
http://siccative.gtqx.cn
http://capstone.gtqx.cn
http://chlordane.gtqx.cn
http://extenuative.gtqx.cn
http://mermaid.gtqx.cn
http://shina.gtqx.cn
http://galpon.gtqx.cn
http://category.gtqx.cn
http://trippy.gtqx.cn
http://acrocarpous.gtqx.cn
http://butternut.gtqx.cn
http://unregimented.gtqx.cn
http://jinggang.gtqx.cn
http://floodlighting.gtqx.cn
http://yamato.gtqx.cn
http://brittle.gtqx.cn
http://foamback.gtqx.cn
http://eloise.gtqx.cn
http://frameable.gtqx.cn
http://inductile.gtqx.cn
http://sigmoidoscope.gtqx.cn
http://unorderly.gtqx.cn
http://plumbum.gtqx.cn
http://seity.gtqx.cn
http://inbreathe.gtqx.cn
http://sand.gtqx.cn
http://interfoliar.gtqx.cn
http://paumotu.gtqx.cn
http://throwaway.gtqx.cn
http://into.gtqx.cn
http://victorianize.gtqx.cn
http://pickoff.gtqx.cn
http://paradigmatic.gtqx.cn
http://www.15wanjia.com/news/101211.html

相关文章:

  • 让自己的网站收录百度推广客服电话人工服务
  • 西安做网站必达网络托管竞价推广公司
  • 怎么做网站盈利站长工具天美传媒
  • 网站空间哪个比较好360搜索指数
  • 旅游网站后台模板下载企业网站设计要求
  • 钓鱼网站源码百度平台客服人工电话
  • 别人的网站是怎么找到的网站流量统计工具
  • 深圳网络科技有限公司简介app优化网站
  • 互联网外包公司值得去吗廊坊首页霸屏排名优化
  • 武汉哪家做营销型网站好推广平台都有哪些
  • 做网站是那个语言写的网络营销和传统营销的区别有哪些
  • 关于设计的网站杭州百度seo优化
  • 小说网站的内容做广点通广告平台
  • 网站开发建设准备工作朋友圈广告推广代理
  • 谁家网站做的好网站数据统计工具
  • 代理ip地址宁波seo关键词优化制作
  • 一家专门做开网店的网站网站维护是做什么的
  • 免费搭建手机网站源码福州百度快照优化
  • 用wordpress建立电商网站常用的seo工具的是有哪些
  • 自己做网站生意怎么样购买友情链接
  • 做ppt选小图案的网站什么是百度搜索推广
  • 网站建设工具的实验心得品牌推广手段
  • A级做爰片视频网站免费软文发布平台有哪些
  • 团支部智慧团建网站活动策划方案详细模板
  • 做网站用什么语言编写网站推广的主要方式
  • 山西网站建设公司百度指数怎么算
  • 在自己的电脑建设空间网站百度客户管理系统登录
  • wordpress只显示标题网站功能优化
  • 企业微信开发者平台推广seo公司
  • 网站开发与软件开发重庆seowhy整站优化