4 Star 6 Fork 3

CreateIt/PyQt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AutoRestart.py 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
Irony 提交于 2019-02-01 23:41 . update
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2017年3月31日
@author: Irony."[讽刺]
@site: https://pyqt5.com , https://github.com/892768447
@email: 892768447@qq.com
@file: AutoRestart
@description:
'''
from optparse import OptionParser
import os
import sys
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout
canRestart = True
def restart(twice):
os.execl(sys.executable, sys.executable, *[sys.argv[0], "-t", twice])
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.resize(400, 400)
layout = QHBoxLayout(self)
self.buttonRestart = QPushButton(
"app start...%s...twice\napp pid: %s\n点击按钮重启...\n" %
(options.twice, os.getpid()), self)
self.buttonRestart.clicked.connect(self.close)
self.buttonExit = QPushButton('退出', self, clicked=self.doExit)
layout.addWidget(self.buttonRestart)
layout.addWidget(self.buttonExit)
def doExit(self):
global canRestart
canRestart = False
self.close()
if __name__ == "__main__":
parser = OptionParser(usage="usage:%prog [optinos] filepath")
parser.add_option("-t", "--twice", type="int",
dest="twice", default=1, help="运行次数")
options, _ = parser.parse_args()
app = QApplication(sys.argv)
w = Window()
w.show()
app.exec_()
if canRestart:
restart(str(options.twice + 1))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/createit/PyQt.git
git@gitee.com:createit/PyQt.git
createit
PyQt
PyQt
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385