1 Star 0 Fork 308

Zander / PyQt

forked from PyQt5 / PyQt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
FadeInOut.py 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
Irony 提交于 2018-12-28 23:09 . update
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QPropertyAnimation
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton
# Created on 2018年6月14日
# author: Irony
# site: https://pyqt5.com , https://github.com/892768447
# email: 892768447@qq.com
# file: FadeInOut
# description:
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = 'Copyright (c) 2018 Irony'
__Version__ = 1.0
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.resize(400, 400)
layout = QVBoxLayout(self)
layout.addWidget(QPushButton('退出', self, clicked=self.doClose))
# 窗口透明度动画类
self.animation = QPropertyAnimation(self, b'windowOpacity')
self.animation.setDuration(1000) # 持续时间1秒
# 执行淡入
self.doShow()
def doShow(self):
try:
# 尝试先取消动画完成后关闭窗口的信号
self.animation.finished.disconnect(self.close)
except:
pass
self.animation.stop()
# 透明度范围从0逐渐增加到1
self.animation.setStartValue(0)
self.animation.setEndValue(1)
self.animation.start()
def doClose(self):
self.animation.stop()
self.animation.finished.connect(self.close) # 动画完成则关闭窗口
# 透明度范围从1逐渐减少到0
self.animation.setStartValue(1)
self.animation.setEndValue(0)
self.animation.start()
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
Python
1
https://gitee.com/Zander-Hwang/PyQt.git
git@gitee.com:Zander-Hwang/PyQt.git
Zander-Hwang
PyQt
PyQt
master

搜索帮助