2024-05-02 17:09:11 发布
网友
我是PyQt的初学者,我放了一个组合框:
select = QtGui.QComboBox(self) select.addItem("San Marcos") select.addItem("San Luis") select.addItem("San Lucas") select.addItem("Rosario I") select.addItem("Rosario II")
如何将每个项目与一个动作联系起来。例如在终端上打印某物。你知道吗
取自here
import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): self.lbl = QtGui.QLabel("Ubuntu", self) combo = QtGui.QComboBox(self) combo.addItem("Ubuntu") combo.addItem("Mandriva") combo.addItem("Fedora") combo.addItem("Red Hat") combo.addItem("Gentoo") combo.move(50, 50) self.lbl.move(50, 150) combo.activated[str].connect(self.onActivated) self.setGeometry(300, 300, 300, 200) self.setWindowTitle('QtGui.QComboBox') self.show() def onActivated(self, text): self.lbl.setText(text) self.lbl.adjustSize() def main(): app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
取自here
相关问题 更多 >
编程相关推荐