Answer the question
In order to leave comments, you need to log in
Is the script only executed once?
In the process of learning PyQt5, I wrote a small interface, the problem is that this thing starts only 1 (ONE!) Time and is treated only by rebooting the system, but, again, once, what to do?
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, qApp
class mainWindow(QMainWindow):
def __init__(self):
super().__init__()
# добавляем панель меню
bar = self.menuBar()
# добавляем на панель меню кнопки
fileBar = bar.addMenu('Файл')
helpBar = bar.addMenu('Помощь')
aboutBar = bar.addMenu('О программе')
exitBar = bar.addMenu('Выход')
# описываем к кнопкам действия
buildGraphAction = QAction('Построить граф', self)
buildGraphAction.setShortcut('Ctrl+G')
exitAppAction = QAction('Закрыть приложение', self)
exitAppAction.setShortcut('Ctrl+E')
# добавляем к кнопкам действие
fileBar.addAction(exitAppAction)
# события
#exitAppAction.triggered.connect(self.exitTrigger)
self.setWindowTitle("ОКНО")
self.resize(600, 400)
self.show()
def exitTrigger(self):
qApp.quit()
if __name__ == '__main__':
app = QApplication(sys.argv)
main = mainWindow()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
Your script doesn't have a while loop that listens for events (Event_loop, Mouse_event, etc.). In windows, you can close the python process through the task manager, but if the process remains when you close the application, then the exitTrigger function is not involved. It should also be in the while loop, just at the
# event location
#exitAppAction.triggered.connect(self.exitTrigger)
output: the script starts the main_window, but there is nothing to close it ))) use an event loop
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question