mac桌面时钟 浮动 (python)

news2024/9/25 1:18:15

浮动时钟,多地时区

app store的都要钱,于是。。。。我们让chatgpt来实现一个吧:

数字:

在这里插入图片描述

代码:

import sys
import datetime
import pytz

from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsView, QGraphicsScene, QGraphicsTextItem, QWidget, QHBoxLayout, QPushButton
from PyQt5.QtCore import QTimer, Qt, QCoreApplication
from PyQt5.QtGui import QColor, QFont, QIcon, QLinearGradient, QBrush



class ClockWidget(QGraphicsView):
    def __init__(self, timezone, location, color):
        super().__init__()

        self.scene = QGraphicsScene(self)
        self.setScene(self.scene)
        self.setGeometry(0, 0, 200, 100)  # Adjust width and height as needed

        # Add city name
        city_font = QFont("Arial", 30, QFont.Bold)
        city_text = QGraphicsTextItem(location)
        city_text.setFont(city_font)
        city_text.setDefaultTextColor(color)
        city_text.setPos(10, 10)  # Adjust position as needed
        self.scene.addItem(city_text)

        # Add digital time
        self.digital_time = QGraphicsTextItem()
        self.digital_time.setFont(QFont("Arial", 30, QFont.Bold))
        self.digital_time.setDefaultTextColor(QColor(255, 215, 0))  # Golden color
        self.digital_time.setPos(10, 50)  # Adjust position as needed
        self.scene.addItem(self.digital_time)

                # Create gradient background
        gradient = QLinearGradient(0, 0, 0, 600)
        gradient.setColorAt(0.0, QColor(0, 0, 0))  # Silver color
        gradient.setColorAt(1.0, QColor(255, 255, 255))  # White color
        self.setBackgroundBrush(QBrush(gradient))



        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update)
        self.timezone = pytz.timezone(timezone)
        self.timer.start(1000)

    def update(self):
        now = datetime.datetime.now(self.timezone)
        time = now.strftime("%H:%M:%S")  # Format time as hour:min:seconds

        # Update digital time
        self.digital_time.setPlainText(time)

        super().update()

class ClockApp(QMainWindow):
    def __init__(self):
        super().__init__()

        # Create the widget container and layout
        self.widget = QWidget()
        self.layout = QHBoxLayout()

        # Create the clock widgets
        self.clock1 = ClockWidget('Asia/Shanghai', 'Beijing', QColor(255, 255, 255))  # Red color for location
        self.clock2 = ClockWidget('Europe/Paris', 'Paris', QColor(255, 255, 255))  # Blue color for location

        # Add clocks to the layout
        self.layout.addWidget(self.clock1)
        self.layout.addWidget(self.clock2)

        # Create Exit button
        # self.exit_button = QPushButton()
        # self.exit_button.setIcon(QIcon('exit.png'))  # Path to the image file for the button
        # self.exit_button.setStyleSheet("background-color: red")
        # self.exit_button.clicked.connect(QCoreApplication.instance().quit)  # Connect button click to exit action

        # Create Exit button
        # Create Exit button
        self.exit_button = QPushButton('X')  # Add 'X' as the button text
        self.exit_button.setStyleSheet(
            "QPushButton {background-color: gray; color: white; font-weight: bold; font-size: 18px; border-radius: 15px; width: 30px; height: 30px;}"
            "QPushButton:pressed {background-color: darkred;}"
        )
        self.exit_button.setFixedSize(30, 30)  # Fix the size of the button
        self.exit_button.clicked.connect(QCoreApplication.instance().quit)  # Connect button click to exit action





        # Add Exit button to the layout
        self.layout.addWidget(self.exit_button)

        # Set layout and window properties
        self.widget.setLayout(self.layout)
        self.setCentralWidget(self.widget)
        self.setGeometry(300, 300, 500, 100)  # Adjust window size as needed
        self.setWindowFlags(Qt.FramelessWindowHint)  # Remove window bar

        # For dragging the window
        self.m_mouse_down = False
        self.m_last_pos = None

    # Mouse press event
    def mousePressEvent(self, event):
        self.m_mouse_down = True
        self.m_last_pos = event.pos()

    # Mouse move event
    def mouseMoveEvent(self, event):
        if self.m_mouse_down:
            self.move(self.pos() + (event.pos() - self.m_last_pos))

    # Mouse release event
    def mouseReleaseEvent(self, event):
        self.m_mouse_down = False

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = ClockApp()
    ex.show()
    sys.exit(app.exec_())

模拟加数字效果:

土豪金效果

代码:


import sys
import datetime
import pytz
from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsView, QGraphicsScene, QGraphicsLineItem, QGraphicsTextItem, QWidget, QHBoxLayout
from PyQt5.QtCore import QTimer, QTime, Qt, QPointF, QPoint
from PyQt5.QtGui import QColor, QTransform, QPen, QFont, QBrush, QLinearGradient

class ClockWidget(QGraphicsView):
    def __init__(self, timezone, color):
        super().__init__()

        self.scene = QGraphicsScene(self)
        self.setScene(self.scene)
        self.setGeometry(0, 0, 300, 300)

        # Define the clock hands with their colors and widths
        self.hour_hand = QGraphicsLineItem(0, 0, 0, -60)
        self.hour_hand.setPen(QPen(QColor(255, 0, 0), 5))  # Red color, width 5
        self.minute_hand = QGraphicsLineItem(0, 0, 0, -80)
        self.minute_hand.setPen(QPen(QColor(0, 255, 0), 4))  # Green color, width 4
        self.second_hand = QGraphicsLineItem(0, 0, 0, -90)
        self.second_hand.setPen(QPen(QColor(0, 0, 255), 3))  # Blue color, width 3

        for hand in [self.hour_hand, self.minute_hand, self.second_hand]:
            hand.setPos(150, 150)
            self.scene.addItem(hand)

        # Add clock ticks
        for i in range(12):
            item = QGraphicsLineItem(0, 0, 0, -100)
            item.setPos(150, 150)
            item.setPen(QPen(QColor(255, 215, 0), 2))
            item.setTransform(QTransform().rotate(i * 30))
            self.scene.addItem(item)



        # Add numbers at top, right, bottom, left positions
        font = QFont("Arial", 16)
        numbers = {'12': QPointF(150, 50), '3': QPointF(250, 150), '6': QPointF(150, 250), '9': QPointF(50, 150)}
        for number, position in numbers.items():
            text_item = QGraphicsTextItem(number)
            text_item.setFont(font)
            text_item.setPos(position)
            self.scene.addItem(text_item)

        # Add city name
        city_font = QFont("Arial", 30)
        city_text = QGraphicsTextItem(timezone)
        city_text.setFont(city_font)
        city_text.setDefaultTextColor(color)
        city_text.setPos(50, 10)  # Adjust position as needed
        self.scene.addItem(city_text)

        # Add digital time
        self.digital_time = QGraphicsTextItem()
        self.digital_time.setFont(QFont("Arial", 30, QFont.Bold))
        self.digital_time.setDefaultTextColor(Qt.black)
        self.digital_time.setPos(60, 260)  # Adjust position as needed
        self.scene.addItem(self.digital_time)

        # Create gradient background
        gradient = QLinearGradient(0, 0, 0, 600)
        gradient.setColorAt(0.0, QColor(192, 192, 192))  # Silver color
        gradient.setColorAt(1.0, QColor(255, 255, 255))  # White color
        self.setBackgroundBrush(QBrush(gradient))

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update)
        self.timezone = pytz.timezone(timezone)
        self.timer.start(1000)

    def update(self):
        now = datetime.datetime.now(self.timezone)
        time = QTime(now.hour, now.minute, now.second)

        self.hour_hand.setTransform(QTransform().rotate(30.0 * (time.hour() + time.minute() / 60.0)))
        self.minute_hand.setTransform(QTransform().rotate(6.0 * (time.minute() + time.second() / 60.0)))
        self.second_hand.setTransform(QTransform().rotate(6.0 * time.second()))

        # Update digital time
        self.digital_time.setPlainText(time.toString())

        super().update()

class ClockApp(QMainWindow):
    def __init__(self):
        super().__init__()

        # Create the widget container and layout
        self.widget = QWidget()
        self.layout = QHBoxLayout()

        # Create the clock widgets
        self.clock1 = ClockWidget('Asia/Shanghai', QColor(255, 0, 0))
        self.clock2 = ClockWidget('Europe/Paris', QColor(0, 0, 255))

        # Add clocks to the layout
        self.layout.addWidget(self.clock1)
        self.layout.addWidget(self.clock2)

        # Set layout and window properties
        self.widget.setLayout(self.layout)
        self.setCentralWidget(self.widget)
        self.setGeometry(300, 300, 600, 350)  # Adjusts window size. Format: (x_position, y_position, width, height)
        self.setWindowFlags(Qt.FramelessWindowHint)  # Remove window bar

        # For dragging the window
        self.m_mouse_down = False
        self.m_last_pos = QPoint()

    # Mouse press event
    def mousePressEvent(self, event):
        self.m_mouse_down = True
        self.m_last_pos = event.pos()

    # Mouse move event
    def mouseMoveEvent(self, event):
        if self.m_mouse_down:
            self.move(self.pos() + (event.pos() - self.m_last_pos))

    # Mouse release event
    def mouseReleaseEvent(self, event):
        self.m_mouse_down = False

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = ClockApp()
    ex.show()
    sys.exit(app.exec_())

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/731823.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

深度学习不同数据增广方法的选用分析

一般情况下,可以将数据扩增方法分为单数据变形、多数据混合、学习数据分布规律生成新数据和学习增广策略等4 类方法。以上顺序也在一定程度上反映了数据增广方法的发展历程。如果与Shorten和Khoshgoftaar的成果对照,就图像数据而言,基于数据变…

抖音矩阵源码搭建开发技术部署分析

目录 一、 什么是抖音矩阵?源码搭建开发注意事项? 1. 抖音矩阵概述 2. 源码搭建开发注意事项: 二、 使用步骤及开发代码展示 一、 什么是抖音矩阵?源码搭建开发注意事项? 1. 抖音矩阵概述 首先,抖音账…

21夜间车牌识别(matlab程序)

1.简述 简单说一下实现思路: 读取图片,转灰度,计算灰度直方图,估算阈值(这里的阈值计算很重要,经过阈值算法,选取一个最恰当的阈值),之后二值化。显示图像即可。 实现目…

爬虫爬取公众号文章

前言 自从chatGPT出现后,对于文本处理的能力直接上升了一个维度。在这之前,我们爬取到网络上的文本内容之后,都需要写一个文本清理的程序,对文本进行清洗,而现在,有了chatGPT的加持,我们只需要…

解决程序占用较多内存的问题

今天发现自己开发的一个程序占用了大量内存而且不会自动释放 ,我的程序在windows中运行的,解决办法如下: 第一步:打开任务管理器,打到正在运行程序 (这里以sql server为例),然后右击…

设计合并排序算法实现对N个整数排序。

1.题目 设计合并排序算法实现对N个整数排序 2.设计思路 先将无序序列利用分治法划分为子序列,直至每个子序列只有一个元素,然后再对有序子序列逐步进行合并排序。合并方法是循环的将两个有序子序列当前的首元素进行比较,较小的元素取出,置入合并序列的左边空置位,直至其中…

特征选择算法 | Matlab 基于最大相关最小冗余特征选择算法(mRMR)的分类数据特征选择

文章目录 效果一览文章概述部分源码参考资料效果一览 文章概述 特征选择算法 | Matlab 基于最大相关最小冗余特征选择算法(mRMR)的分类数据特征选择 部分源码 %--------------------

Redis实战案例12-添加秒杀券实现秒杀下单及相关问题解决

1. 添加优惠券 该项目没有后台管理的界面,所以采用postman发送请求 http://localhost:8081/voucher/seckill注意end时间要大于当前系统时间 {"shopId": 2,"title": "100元代金券","subTitle": "周一至周五均可使用&qu…

c++查漏补缺

c语言的struct只能包含变量,而c中的class除了包含变量,还可以包含函数。 通过结构体定义出来的变量还是变量,而通过类定义出来有了新的名称,叫做对象。C语言中,会将重复使用或具有某项功能的代码封装成一个函数&#x…

【剑指offer】8. 斐波那契数列(java)

文章目录 斐波那契数列描述输入描述:返回值描述:示例1示例2示例3思路非递归递归 完整代码 斐波那契数列 描述 大家都知道斐波那契数列,现在要求输入一个正整数 n ,请你输出斐波那契数列的第 n 项。 斐波那契数列是一个满足 f …

PHP学生工作平台管理系统mysql数据库web结构apache计算机软件工程网页wamp

一、源码特点 PHP学生工作平台管理系统 是一套完善的web设计系统,对理解php编程开发语言有帮助,系统具有完整的源代码和数据库,系统主要采用B/S模式开发。开发环境为PHP APACHE,数据 库为mysql5.0,使用php语言开发…

linux 如何挂载fat32格式u盘,如何挂载NTFS 文件系统的硬盘

linux系统默认可以识别fat32u盘,对ntfs格式u盘不能识别 具体挂载方式如下 1、插入u盘 2、mkdir /mnt/usb 此命令用于创建挂载u盘的目录,只需创建一次就可以,若已经存在则不需要再次创建 3、fdisk -l 找到u盘路径 上图显示的sdb1,sdb2,sdb5…

Gradio,我们可以为我们的模型创建Web界面

Gradio是一个Python库,允许我们快速为机器学习模型创建可定制的接口。 使用Gradio,我们可以为我们的模型创建Web界面,而无需编写任何HTML,CSS或JavaScript。 Gradio旨在与广泛的机器学习框架配合使用,包括TensorFlow&a…

IOU发展历程学习记录

概述 IOU的出现主要最先运用在预测bbox框和target bbox框之间的重叠问题,为NMS提供相应的数值支撑。另外在bbox框的回归问题上,由于L1 Loss存在如下问题:当损失函数对x的导数为常数,在训练后期,x很小时,若…

GEE:基于MODIS土地覆盖类型“混交林”的净初级生产力(NPP)的区域统计

作者:CSDN @ _养乐多_ 本文将介绍如何使用Google Earth Engine(GEE)平台提取特定地区的净初级生产力(NPP)的统计信息,并在地图上可视化。通过加载MODIS数据集,并使用GEE提供的函数和方法,能够高效地计算特定地区的净初级生产力的平均值。 文章目录 一、代码详解二、代…

大模型的数据供血系统-向量数据库常识科普

1. 数据库行业有了新动向 对于传统数据库研发运维来说,数据库行业上次有概念创新,还是十几年前的NoSQL…… 在AI大行业发展的推进下,向量数据库成为了最新兴的数据库技术趋势,业内多家开源向量数据库都拿到了高额融资,…

《网络是怎样连接的》-户根勤

第一章:浏览器生成消息-探索浏览器内部 主要讲HTTP消息、DNS和委托协议栈发送消息。 第二章:用电信号传输TCP/IP数据-探索协议栈和网卡 主要讲套接字的创建、连接、通信、断开和删除四个阶段;IP与以太网的包收发阶段;UDP协议的收…

使用LocalThread获取当前线程的用户ID错误

说明:LocalThread是线程变量,可以往该线程变量中填充我们项目用户的ID,可以在其他的业务代码中直接获取,十分方便,详细参考:http://t.csdn.cn/k75rs LocalThread使用 第一步:创建类 创建一个…

北京市自动驾驶出行服务商业化试点启动,无人驾驶会是未来吗?

北京市高级级别自动驾驶示范区工作办公室公告称,智能网联乘用车“车内无人”商业化试点正式启动。根据最新修订的《北京市智能网联汽车政策先行区自动驾驶出行服务商业化试点管理细则(试行)》,企业在满足相关要求后,可…

如何用https协议支持小程序

步骤一:下载SSL证书 登录数字证书管理服务控制台。在左侧导航栏,单击SSL 证书。在SSL证书页面,定位到目标证书,在操作列,单击下载。 在服务器类型为Nginx的操作列,单击下载。 解压缩已下载的SSL证书压缩…