플밍

콤보박스 예제 본문

프로그래밍/PyQT

콤보박스 예제

너구리안주 2015. 12. 13. 13:51


여러가지 방법이 있지만 그 중에 하나

#ads_1

class Example(QWidget):

    def __init__(self):

        super().__init__()

        self.initUI()


    def initUI(self):

        self.lbl = QLabel(self)

        self.lbl.move(50, 50)

        combo = QComboBox(self)

        combo.addItem("독수리", "eagle")

        combo.addItem("강아지", "puppy")

        combo.addItem("고양이", "cat")

        combo.move(50, 100)

        combo.activated[str].connect(self.changeCombo)

        

        self.setGeometry(300, 300, 300, 200)

        self.setWindowTitle('QSplitter')

        self.show()


    def changeCombo(self, text):

        sender = self.sender()

        idx = sender.currentIndex()

        self.lbl.setText(sender.itemData(idx))

        self.lbl.adjustSize()


if __name__ == '__main__':

    app = QApplication(sys.argv)

    ex = Example()

    sys.exit(app.exec_())

#ads_2

Comments