import
  
    
  sys
  
   from
  
  PyQt5
  
   .
  
  QtWidgets
  
   import
  
  QPushButton
  
   ,
  
  QApplication
  
   ,
  
  QDesktopWidget
  
   from
  
  PyQt5
  
   .
  
  QtWidgets
  
   import
  
  QWidget
  
   from
  
  PyQt5
  
   import
  
  QtCore
  
   ,
  
  QtGui
  
   ,
  
  QtWidgets
  
   ,
  
  Qt
  
   import
  
  time
currentTime
  
   =
  
  time
  
   .
  
  strftime
  
   (
  
  
   "%H:%M %p"
  
  
   )
  
  
  
   class
  
  
   Toast
  
  
   (
  
  QWidget
  
   )
  
  
   :
  
  
   def
  
  
   __init__
  
  
   (
  
  self
  
   )
  
  
   :
  
  
   super
  
  
   (
  
  
   )
  
  
   .
  
  __init__
  
   (
  
  
   )
  
  self
  
   .
  
  setWindowTitle
  
   (
  
  
   'toast'
  
  
   )
  
  self
  
   .
  
  setWindowFlags
  
   (
  
  Qt
  
   .
  
  Qt
  
   .
  
  FramelessWindowHint
  
   )
  
  
  self
  
   .
  
  setStyleSheet
  
   (
  
  
   "background-color:#3A4659;\n"
  
  
   )
  
  self
  
   .
  
  gridLayout_3
  
   =
  
  QtWidgets
  
   .
  
  QGridLayout
  
   (
  
  self
  
   )
  
  self
  
   .
  
  gridLayout_3
  
   .
  
  setContentsMargins
  
   (
  
  
   0
  
  
   ,
  
  
   0
  
  
   ,
  
  
   0
  
  
   ,
  
  
   0
  
  
   )
  
  
  self
  
   .
  
  gridLayout_3
  
   .
  
  setObjectName
  
   (
  
  
   "gridLayout_3"
  
  
   )
  
  self
  
   .
  
  frame
  
   =
  
  QtWidgets
  
   .
  
  QFrame
  
   (
  
  self
  
   )
  
  
  self
  
   .
  
  frame
  
   .
  
  setObjectName
  
   (
  
  
   "frame"
  
  
   )
  
  self
  
   .
  
  gridLayout_2
  
   =
  
  QtWidgets
  
   .
  
  QGridLayout
  
   (
  
  self
  
   .
  
  frame
  
   )
  
  self
  
   .
  
  gridLayout_2
  
   .
  
  setObjectName
  
   (
  
  
   "gridLayout_2"
  
  
   )
  
  self
  
   .
  
  horizontalLayout
  
   =
  
  QtWidgets
  
   .
  
  QHBoxLayout
  
   (
  
  
   )
  
  self
  
   .
  
  horizontalLayout
  
   .
  
  setObjectName
  
   (
  
  
   "horizontalLayout"
  
  
   )
  
  self
  
   .
  
  passLabel
  
   =
  
  QtWidgets
  
   .
  
  QLabel
  
   (
  
  self
  
   .
  
  frame
  
   )
  
  self
  
   .
  
  passLabel
  
   .
  
  setMinimumSize
  
   (
  
  QtCore
  
   .
  
  QSize
  
   (
  
  
   41
  
  
   ,
  
  
   41
  
  
   )
  
  
   )
  
  self
  
   .
  
  passLabel
  
   .
  
  setMaximumSize
  
   (
  
  QtCore
  
   .
  
  QSize
  
   (
  
  
   41
  
  
   ,
  
  
   41
  
  
   )
  
  
   )
  
  
  
  self
  
   .
  
  passLabel
  
   .
  
  setObjectName
  
   (
  
  
   "label_4"
  
  
   )
  
  self
  
   .
  
  horizontalLayout
  
   .
  
  addWidget
  
   (
  
  self
  
   .
  
  passLabel
  
   )
  
  self
  
   .
  
  gridLayout
  
   =
  
  QtWidgets
  
   .
  
  QGridLayout
  
   (
  
  
   )
  
  self
  
   .
  
  gridLayout
  
   .
  
  setObjectName
  
   (
  
  
   "gridLayout"
  
  
   )
  
  
  self
  
   .
  
  alertsLabel
  
   =
  
  QtWidgets
  
   .
  
  QLabel
  
   (
  
  self
  
   .
  
  frame
  
   )
  
  self
  
   .
  
  alertsLabel
  
   .
  
  setMinimumSize
  
   (
  
  QtCore
  
   .
  
  QSize
  
   (
  
  
   200
  
  
   ,
  
  
   0
  
  
   )
  
  
   )
  
  
  self
  
   .
  
  alertsLabel
  
   .
  
  setStyleSheet
  
   (
  
  
   "font: 20px\"微软雅黑\";color:white"
  
  
   )
  
  self
  
   .
  
  alertsLabel
  
   .
  
  setText
  
   (
  
  
   "消息通知"
  
  
   )
  
  self
  
   .
  
  alertsLabel
  
   .
  
  setObjectName
  
   (
  
  
   "label"
  
  
   )
  
  self
  
   .
  
  gridLayout
  
   .
  
  addWidget
  
   (
  
  self
  
   .
  
  alertsLabel
  
   ,
  
  
   0
  
  
   ,
  
  
   0
  
  
   ,
  
  
   1
  
  
   ,
  
  
   1
  
  
   )
  
  
  self
  
   .
  
  timeLabel
  
   =
  
  QtWidgets
  
   .
  
  QLabel
  
   (
  
  self
  
   .
  
  frame
  
   )
  
  self
  
   .
  
  timeLabel
  
   .
  
  setStyleSheet
  
   (
  
  
   "font: 15px\"微软雅黑\";color:white"
  
  
   )
  
  self
  
   .
  
  timeLabel
  
   .
  
  setAlignment
  
   (
  
  QtCore
  
   .
  
  Qt
  
   .
  
  AlignRight
  
   |
  
  QtCore
  
   .
  
  Qt
  
   .
  
  AlignTrailing
  
   |
  
  QtCore
  
   .
  
  Qt
  
   .
  
  AlignVCenter
  
   )
  
  self
  
   .
  
  timeLabel
  
   .
  
  setText
  
   (
  
  currentTime
  
   )
  
  
  self
  
   .
  
  timeLabel
  
   .
  
  setObjectName
  
   (
  
  
   "label_3"
  
  
   )
  
  self
  
   .
  
  gridLayout
  
   .
  
  addWidget
  
   (
  
  self
  
   .
  
  timeLabel
  
   ,
  
  
   0
  
  
   ,
  
  
   1
  
  
   ,
  
  
   1
  
  
   ,
  
  
   1
  
  
   )
  
  
  self
  
   .
  
  toastLabel
  
   =
  
  QtWidgets
  
   .
  
  QLabel
  
   (
  
  self
  
   .
  
  frame
  
   )
  
  self
  
   .
  
  toastLabel
  
   .
  
  setStyleSheet
  
   (
  
  
   "font: 15px\"微软雅黑\";color:white"
  
  
   )
  
  
  self
  
   .
  
  toastLabel
  
   .
  
  setObjectName
  
   (
  
  
   "label"
  
  
   )
  
  self
  
   .
  
  gridLayout
  
   .
  
  addWidget
  
   (
  
  self
  
   .
  
  toastLabel
  
   ,
  
  
   1
  
  
   ,
  
  
   0
  
  
   ,
  
  
   1
  
  
   ,
  
  
   1
  
  
   )
  
  self
  
   .
  
  horizontalLayout
  
   .
  
  addLayout
  
   (
  
  self
  
   .
  
  gridLayout
  
   )
  
  self
  
   .
  
  gridLayout_2
  
   .
  
  addLayout
  
   (
  
  self
  
   .
  
  horizontalLayout
  
   ,
  
  
   0
  
  
   ,
  
  
   0
  
  
   ,
  
  
   1
  
  
   ,
  
  
   1
  
  
   )
  
  self
  
   .
  
  gridLayout_3
  
   .
  
  addWidget
  
   (
  
  self
  
   .
  
  frame
  
   ,
  
  
   0
  
  
   ,
  
  
   0
  
  
   ,
  
  
   1
  
  
   ,
  
  
   1
  
  
   )
  
  
   class
  
  
   WinForm
  
  
   (
  
  QWidget
  
   )
  
  
   :
  
  
   def
  
  
   __init__
  
  
   (
  
  self
  
   ,
  
  parent
  
   =
  
  
   None
  
  
   )
  
  
   :
  
  
   super
  
  
   (
  
  WinForm
  
   ,
  
  self
  
   )
  
  
   .
  
  __init__
  
   (
  
  parent
  
   )
  
  self
  
   .
  
  setGeometry
  
   (
  
  
   300
  
  
   ,
  
  
   300
  
  
   ,
  
  
   350
  
  
   ,
  
  
   350
  
  
   )
  
  
  self
  
   .
  
  resize
  
   (
  
  
   350
  
  
   ,
  
  
   350
  
  
   )
  
  self
  
   .
  
  setWindowTitle
  
   (
  
  
   '点击按钮开启弹窗'
  
  
   )
  
  
  quit
  
   =
  
  QPushButton
  
   (
  
  
   '开启弹窗'
  
  
   ,
  
  self
  
   )
  
  
  quit
  
   .
  
  setGeometry
  
   (
  
  
   10
  
  
   ,
  
  
   10
  
  
   ,
  
  
   100
  
  
   ,
  
  
   35
  
  
   )
  
  
  quit
  
   .
  
  setStyleSheet
  
   (
  
  
   "background-color: red"
  
  
   )
  
  
  quit
  
   .
  
  clicked
  
   .
  
  connect
  
   (
  
  self
  
   .
  
  toast
  
   )
  
  
   def
  
  
   toast
  
  
   (
  
  self
  
   )
  
  
   :
  
  self
  
   .
  
  ui
  
   =
  
  Toast
  
   (
  
  
   )
  
  self
  
   .
  
  ui
  
   .
  
  show
  
   (
  
  
   )
  
  QtCore
  
   .
  
  QTimer
  
   (
  
  
   )
  
  
   .
  
  singleShot
  
   (
  
  
   2000
  
  
   ,
  
  self
  
   .
  
  ui
  
   .
  
  close
  
   )
  
  self
  
   .
  
  ui
  
   .
  
  toastLabel
  
   .
  
  setText
  
   (
  
  
   '保存成功'
  
  
   )
  
  self
  
   .
  
  ui
  
   .
  
  passLabel
  
   .
  
  setPixmap
  
   (
  
  QtGui
  
   .
  
  QPixmap
  
   (
  
  
   "images/pass.png"
  
  
   )
  
  
   )
  
  screen
  
   =
  
  QDesktopWidget
  
   (
  
  
   )
  
  
   .
  
  screenGeometry
  
   (
  
  
   )
  
  size
  
   =
  
  self
  
   .
  
  ui
  
   .
  
  geometry
  
   (
  
  
   )
  
  self
  
   .
  
  ui
  
   .
  
  move
  
   (
  
  
   (
  
  screen
  
   .
  
  width
  
   (
  
  
   )
  
  
   -
  
  size
  
   .
  
  width
  
   (
  
  
   )
  
  
   )
  
  
   /
  
  
   2
  
  
   ,
  
  
   (
  
  screen
  
   .
  
  height
  
   (
  
  
   )
  
  
   -
  
  size
  
   .
  
  height
  
   (
  
  
   )
  
  
   )
  
  
   /
  
  
   2
  
  
   )
  
  
   if
  
  __name__
  
   ==
  
  
   "__main__"
  
  
   :
  
  app
  
   =
  
  QApplication
  
   (
  
  sys
  
   .
  
  argv
  
   )
  
  win
  
   =
  
  WinForm
  
   (
  
  
   )
  
  
  win
  
   .
  
  show
  
   (
  
  
   )
  
  sys
  
   .
  
  exit
  
   (
  
  app
  
   .
  
  exec_
  
   (
  
  
   )
  
  
   )
  
  # # -*- encoding: utf-8 -*-#import sysfrom PyQt5.QtWidgets import QPushButton, QApplication,QDesktopWidgetfrom PyQt5.QtWidgets import  QWidgetfrom PyQt5 import QtCore, QtGui, QtWidgets, Qtimport timecurrentTime = time.strftime("%H:%M %p")  # 当前时间(时
import sys
from PyQt5.QtWidgets import QPushButton, QApplication,QDesktopWidget
from PyQt5.QtWidgets import  QWidget
from PyQt5 import QtCore, QtGui, QtWidgets, Qt
import time
currentTime = time.strftime("%H:%M %p")  # 当前时间(.
消息框会
  
   消失
  
  ,因为代码中调用的是QMessageBox的show方法,该方法并没有保留对它的引用,所以一旦函数返回,它就会被垃圾回收
调用QMessageBox的exec_()代替show方法显示弹窗
box = QMessageBox()
box.setIcon(1)
box.setWindowTitle("温馨提示")
box.setText("运行环境检测ok!")
# 添加按钮,可用中文
yes = box.addButton('确定', QMessageBox.YesRo
  
   https://blog.csdn.net/u013782830/article/details/51755571
思路:设置
   
    一个
   
   定时器,去改变label的可见度,或者到时直接隐藏
定时器时间,默认3s,之后隐藏提示
timecount = 3
def onSure_but(self):
    self.timecount = 3
    self.timer = QTimer(self)
    input_mess = self.inputlineEdit.text()
在这个视图函数中,我们使用Django的`render`函数来渲染
   
    一个
   
   名为`index.html`的模板。
接下来,在你的模板文件`index.html`中,使用以下代码来引入JavaScript代码:
```html
{% extends 'base.html' %}
{% block content %}
  <!-- 在这里编写页面内容 -->
{% endblock %}
{% block scripts %}
  <script>
    alert('欢迎访问我的网站!');
  </script>
{% endblock %}
在`scripts`模板块中,我们使用了JavaScript的`alert`函数来
   
    弹出
   
   
    一个
   
   
    提示框
   
   ,里面包含了欢迎
   
    信息
   
   。
最后,在你的`base.html`模板文件中,定义
   
    一个
   
   名为`scripts`的空块,用于在子模板中插入JavaScript代码:
```html
<!DOCTYPE html>
    <title>{% block title %}My Website{% endblock %}</title>
  </head>
    <header>
      <!-- 在这里编写网站头部 -->
    </header>
      {% block content %}
        <!-- 在这里编写页面内容 -->
      {% endblock %}
    </main>
    <footer>
      <!-- 在这里编写网站底部 -->
    </footer>
    {% block scripts %}{% endblock %}
  </body>
</html>
这样,当你访问这个视图函数所对应的URL时,就会
   
    弹出
   
   
    一个
   
   
    提示框
   
   ,里面显示欢迎
   
    信息
   
   。