【发布时间】:2021-05-05 23:26:01
【问题描述】:
我想知道是否有一种 Python 方法可以防止应用程序的多个实例运行。假设如果应用程序已经在运行,那么用户一定不能再次启动同一个应用程序。
这是一个示例 PyQt5 代码。
import sys
from PyQt5.QtWidgets import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Using Labels")
self.setGeometry(50,50,350,350)
self.UI()
def UI(self):
text1=QLabel("Hello Python",self)
text2=QLabel("Hello World",self)
text1.move(50,50)
text2.move(200,150)
self.show()
def main():
App = QApplication(sys.argv)
window=Window()
sys.exit(App.exec_())
if __name__ == '__main__':
main()
我遇到了这个solution,它使用了这个tendo 模块/库。虽然答案完美,但我不想为这样一个微不足道的问题安装另一个依赖项。
我正在为 Windows 系统开发我的应用程序,但如果答案是跨平台的,我将不胜感激。
【问题讨论】:
标签: python python-3.x pyqt pyqt5