1 py 代码
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtCore import QTimer
import os
class ReminderWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Reminder')
self.setGeometry(100, 100, 300, 200)
self.label = QLabel(self)
self.label.setGeometry(50, 50, 200, 100)
def show_and_close(self):
self.show() # 显示弹窗
QTimer.singleShot(50000, self.close) # 50秒后关闭
def get_desktop_file_content():
# 获取后端数据 --> 下面是获取静态文件内容,可以替换成后端数据
file_path ='D:/360MoveData/py.txt' # 显示的文件
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
else:
return '文件读取失败'
if __name__ == '__main__':
app = QApplication(sys.argv)
window = ReminderWindow()
window.label.setText(get_desktop_file_content())
window.show_and_close()
sys.exit(app.exec_())
2 打包py
pip install pyinstaller
# 先转到py指定文件夹
cmd
cd /d D:\360MoveData
pyinstaller --onefile your_script_name.py
3 设置开机自启
1 Win + R 组合键打开 "运行" 对话框。输入 shell:startup 并点击 "确定" 打开 "启动" 文件夹。
2 将打包的exe拖放到 "启动" 文件夹中。 文件在dist文件夹中,如果不是用绝对路径要把txt文件另处理
3 重新启动计算机,Python脚本将会在系统启动时自动运行。