'PyQT5 Python and Visual code studio : Windows close after init

:-) i got an issue with my code by using the software Visual Code Studio. The code (below) is working nice by using the default Python IDLE shell but when i run it into Visual code studio, the generated windows (by my code) close automatically after the initializing of my code..There's no error code or warning code. The software (visual code studio was set to my PYTHON default install software, extension PyQT5 was installed in VCS...

Have you got any ideas? Big thanks!!

here my code :

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction,QLineEdit,QLabel
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QMessageBox

class App(QMainWindow):
    def __init__(self):
       super().__init__()
       self.title = 'AW-GENKA'
       self.left = 100
       self.top = 100
       self.width = 640
       self.height = 400
       self.initUI()
       self.msg = QMessageBox()
    def initUI(self):
       self.setWindowTitle(self.title)
       self.setGeometry(self.left,self.top,self.width,self.height)
       mainMenu=self.menuBar()
       fileMenu=mainMenu.addMenu('File')
       editMenu=mainMenu.addMenu('Edit')
       viewMenu=mainMenu.addMenu('Preview')
       searchMenu=mainMenu.addMenu('Template')
       toolsMenu=mainMenu.addMenu('Outils')
#------pour ajouter une sous menu self.XXX renvoi vers def XXX--------
       mod1 =QAction('Get Photo', self)
       mod1.triggered.connect(self.mod1)
       toolsMenu.addAction (mod1)
       mod2 =QAction('Preview', self)
       mod2.triggered.connect(self.mod2)
       toolsMenu.addAction (mod2)
#structure d'un modele--------------------------------
#      mod2 =QAction('mod2', self)
#      mod2.triggered.connect(self.mod2)
#      toolsMenu.addAction (mod2)
#----------------------------------------------------
       helpMenu=mainMenu.addMenu('Help')
       help =QAction('About', self)
       help.triggered.connect(self.help)
       helpMenu.addAction (help)
       exitButton=QAction('Exit', self)
       exitButton.setShortcut('Ctrl+Q')
       exitButton.setStatusTip('Exit application')
       exitButton.triggered.connect(self.close)
       fileMenu.addAction(exitButton)
       self.nameLabel = QLabel(self)
       
       self.nameLabel.setText('Name:')
       self.line = QLineEdit(self)

       self.line.move(80,40)
       self.line.resize(200, 32)
       self.nameLabel.move(40, 40)
       

       self.show()

       #textboxValue = self.textbox.text() 

    def mod1(self):
       print("Appel SSH")
       

    def mod2(self):
       print("Nok")


    def help(self):
        msg = QMessageBox(self)
        msg.setWindowTitle("About...")
        msg.setText("Copyright 2022")
        button = msg.exec()
        
         
      
if __name__=='__main__':
   app=QApplication(sys.argv)
   ex=App() 

Well, i think the issue is coming from ex= APP() ?

Regards!!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source