Python drop-down box

I looked at the password is to explain the friends must know, drop-down box inside a man named knowledge, and today I will say something about the drop-down box.

from PyQt5.QtWidgets import QWidget, QLabel, QComboBox, QApplication
import sys

class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.settings()

    def settings(self):
        self.a = QLabel("请选择学科", self)
        self.a.move(20, 50)
        self.b = QComboBox(self)
        self.b.addItem("数学")
        self.b.addItem("语文")
        self.b.addItem("英语")
        self.b.move(100, 50)

        self.b.activated[str].connect(self.printresult)
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('下拉选框')
        self.show()

    def printresult(self, text):
        self.a.setText(text)
        print('你选择了{}'.format(text))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

Create a drop-down box with QComboBox. Then add options using addItem.
self.b.activated [str] .connect (self.printresult)
This is the equivalent of binding signal, and then you select the option to return to the parameter binding function. So printresult in, text is the option you choose.

This issue is very simple, but we must master the yo! ! !

Well, this is today's Gui knowledge, if you like, might spend five seconds, plus followers, a point like this. If you have doubts, you can ask in the comments area, partners can also add my QQ: 3,418,772,261 . In the QQ, I can provide a Q & A. So the next issue goodbye, bye!

Published 26 original articles · won praise 85 · views 30000 +

Guess you like

Origin blog.csdn.net/Persia_king/article/details/105291892