PyQt5滚动屏时间选择器
2026-11-29 05:26:58
简介
PyQt5滚动(dong)屏时间选择器是滚动一个基于PyQt5库的图形界面应用程序,用于在滚动屏幕上选择时间,间选用户可以通过滚动屏幕来选择小(xiao)时、择器(qi)分钟和秒,滚动然后点击“确定(ding)”按钮来获取所选时间。间选(图片(pian)来源网络,择器侵删)
安装所(suo)需(xu)库
1、滚动安装PyQt5库:

pip install PyQt52、间选安装QTime库:

pip install QTime实现步骤
1、择器导入所需库:

from PyQt5.QtWidgets import QApplication,滚动 QWidget, QVBoxLayout, QPushButton, QLabel, QTimeEdit, QHBoxLayout, QSliderfrom PyQt5.QtCore import QTime, Qtimport 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) # 创建标签和时间(jian)编辑器 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) # 设置滑动条(tiao)范围为(wei)一天的时间(以秒为(wei)单位) self.slider.valueChanged.connect(self.update_time) layout.addWidget(self.slider) self.confirm_button = QPushButton('确定(ding)') 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'当(dang)前时间:{ 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
(作者:产品中心)
