je nach Auswahl in der Kombobox soll im Label lbl_fachraster entweder das Bild "kragfach_links" oder "kragfach_rechts" angezeigt werden.
Offensichtilch geht es so nicht, das Programmstürzt ab. Was mache ich falsch?
Code: Alles auswählen
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (
QApplication,
QComboBox,
QLabel,
QVBoxLayout,
QWidget,
)
from PyQt5.QtGui import (
QPixmap
)
class Fenster(QWidget):
def __init__(self):
super().__init__()
self.resize(400, 600)
self.cbo_fachraster_typ=QComboBox()
self.cbo_fachraster_typ.addItem("Kragfach links")
self.cbo_fachraster_typ.addItem("Kragfach rechts")
self.cbo_fachraster_typ.addItem("Test-Schaltfläche")
self.cbo_fachraster_typ.activated[str].connect(self.cbo_fachraster_change)
pic_kragfach_links = QPixmap(".\kragfach_links.png")
pic_kragfach_rechts = QPixmap(".\kragfach_rechts.png")
self.lbl_fachraster = QLabel()
#self.lbl_fachraster.setText("Kragfach links")
self.lbl_fachraster.setPixmap(pic_kragfach_links)
self.layout = QVBoxLayout()
self.layout.setAlignment(Qt.AlignTop)
self.layout.addWidget(self.cbo_fachraster_typ)
self.layout.addWidget(self.lbl_fachraster)
self.setLayout(self.layout)
def cbo_fachraster_change(self, item):
print(item) #Test
if item == "Kragfach rechts":
#self.lbl_fachraster.setText("Kragfach rechts")
self.lbl_fachraster.setPixmap(pic_kragfach_rechts)
if item == "Kragfach links":
#self.lbl_fachraster.setText("Kragfach links")
self.lbl_fachraster.setPixmap(pic_kragfach_links)
pass
def main():
app = QApplication(sys.argv)
fenster = Fenster()
fenster.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()