用python做一个10分钟倒计时QT界面,倒计时开始要显示2秒钟‘答辩开始’,剩余俩分钟的时候屏幕变成黄色,最后十秒钟变成红色,计时结束后要显示‘答辩结束’,QT窗口要能自适应屏幕大小。

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QDesktopWidget
from PyQt5.QtGui import QFont
from PyQt5.QtCore import QTimer, Qt
class Countdown(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('倒计时')
self.setWindowIcon(self.style().standardIcon(1))
self.resize(self.width(), self.height()) # 默认大小
# 窗口居中显示
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
# 垂直布局
layout = QVBoxLayout()
# 显示文字标签
self.label = QLabel('答辩开始

该代码实现了一个QT界面的10分钟倒计时器,开始时显示答辩开始,剩余2分钟时背景变黄,最后10秒变红,结束时显示答辩结束。窗口可自适应屏幕大小,字体大小与屏幕宽度成比例调整。
最低0.47元/天 解锁文章
674

被折叠的 条评论
为什么被折叠?



