SHARE
TWEET

QMessageDialog does not run

a guest Jul 17th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2.  
  3. from PyQt5.QtCore import QLockFile
  4. from PyQt5.QtWidgets import QApplication
  5. from PyQt5.QtWidgets import QMessageBox
  6.  
  7. from window import MainWindow
  8.  
  9.  
  10. if __name__ == "__main__":
  11.     lock_file = QLockFile("app.lock")
  12.  
  13.     try:
  14.         if lock_file.tryLock():
  15.             app_object = QApplication(sys.argv)
  16.  
  17.             window = MainWindow()
  18.             window.show()
  19.  
  20.             app_object.exec()
  21.         else:
  22.             error_message = QMessageBox()
  23.             error_message.setIcon(QMessageBox.Warning)
  24.             error_message.setWindowTitle("Error")
  25.             error_message.setText("Chess Fighter is already running!")
  26.             error_message.setStandardButtons(QMessageBox.Ok)
  27.             error_message.exec()
  28.     finally:
  29.         lock_file.unlock()
  30.  
  31. ### The error I get is:    "QWidget: Must construct a QApplication before a QWidget"  ###
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top