PyQt5滚动屏时间选择器

简介

PyQt5滚动屏时间选择器是一个基于PyQt5库的图形界面应用程序,用于在滚动屏幕上选择时间,用户可以通过滚动屏幕来选择小时、分钟和秒,然后点击“确定”按钮来获取所选时间。

PyQt5滚动屏时间选择器
(图片来源网络,侵删)

安装所需库

1、安装PyQt5库:

pip install PyQt5

2、安装QTime库:

pip install QTime

实现步骤

1、导入所需库:

from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel, QTimeEdit, QHBoxLayout, QSlider
from PyQt5.QtCore import QTime, Qt
import sys

2、创建主窗口类:

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        # 设置窗口标题和大小
        self.setWindowTitle('滚动屏时间选择器')
        self.resize(300, 200)
        # 创建布局管理器
        layout = QVBoxLayout()
        self.setLayout(layout)
        # 创建标签和时间编辑器
        self.time_label = QLabel('请选择时间:')
        self.time_edit = QTimeEdit()
        self.time_edit.setDisplayFormat('HH:mm:ss')
        self.time_edit.timeChanged.connect(self.update_label)
        layout.addWidget(self.time_label)
        layout.addWidget(self.time_edit)
        # 创建滑动条和按钮
        self.slider = QSlider(Qt.Horizontal)
        self.slider.setRange(0, 24 * 60 * 60)  # 设置滑动条范围为一天的时间(以秒为单位)
        self.slider.valueChanged.connect(self.update_time)
        layout.addWidget(self.slider)
        self.confirm_button = QPushButton('确定')
        self.confirm_button.clicked.connect(self.confirm_time)
        layout.addWidget(self.confirm_button)

3、定义槽函数:

    def update_label(self):
        time = self.time_edit.time()
        self.time_label.setText(f'当前时间:{time.toString()}')
    def update_time(self, value):
        total_seconds = int(value) // (60 * 60) * (60 * 60) + int(value) % (60 * 60) * 60 + int(value) % 60 * 1000 / 86400 % 60 * 1000 / 3600 % 60 * 1000 / 60 % 1000 / 100 % 1000 / 10 % 1000 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 10 % 1

原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/479169.html

(0)
未希新媒体运营
上一篇 2024-04-15 14:42
下一篇 2024-04-15 14:44

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购  >>点击进入