Wie schließt man mit PyQt5 erfolgreich ein Fenster?
Mit folgendem Python-Code funktioniert es jedenfalls nicht:
Code: Alles auswählen
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.uic import loadUi
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.exit_button.clicked.connect(self.quit)
if __name__ == '__main__':
app = QApplication(sys.argv)
app_window = loadUi("test.ui")
app_window.show()
sys.exit(app.exec_())
test.ui
Code: Alles auswählen
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>481</width>
<height>329</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="exitButton">
<property name="geometry">
<rect>
<x>190</x>
<y>130</y>
<width>117</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Exit</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>481</width>
<height>28</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Atalanttore