下拉列表框QComboBox

学习PyQt推荐大家看这本书:https://weread.qq.com/web/reader/6393267071ccfa97639f573

链接:https://pan.baidu.com/s/1nCMoIL_iXYmcZS9Q58QG6g 
提取码:odcg 

import sys
from PyQt5.QtWidgets import QApplication,QWidget 
from PyQt5 import QtCore
from PyQt5.QtCore import pyqtSlot
 
from ui_Widget import Ui_Widget
class QmyWidget(QWidget):
    def __init__(self,parent=None):
        super().__init__(parent)
        self.ui=Ui_Widget()
        self.ui.setupUi(self)
    
    def on_btnIniItems_clicked(self):
        self.ui.comboBox.clear()
        provinces=["山东","河北","河南","湖北","湖南","广东"]
        self.ui.comboBox.addItems(provinces)

    def on_btnClear_clicked(self):
        self.ui.comboBox.clear()
    @pyqtSlot(bool)
    def on_chkBoxEditable_clicked(self,checked):
        self.ui.comboBox.setEditable(checked)
    @pyqtSlot(str)
    def on_comboBox_currentIndexChanged(self,curText):
        self.ui.lineEdit.setText(curText)
    
    def on_btnIni2_clicked(self):
        self.ui.comboBox2.clear()
        cities={"北京":10,"上海":21,"天津":22,"徐州":516,"福州":591,"青岛":532}
        # self.ui.comboBox2.addItems(cities)
        for k in cities:
            self.ui.comboBox2.addItem(k,cities[k])
    @pyqtSlot(str)
    def on_comboBox2_currentIndexChanged(self,curText):
        self.ui.lineEdit.setText(curText)
        zone=self.ui.comboBox2.currentData()
        if(zone!=None):
            self.ui.lineEdit.setText(curText+":区号=%d"%zone)
        
if __name__=="__main__":
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)#自适应缩放
    app=QApplication(sys.argv)
    form=QmyWidget()
    form.show()
    sys.exit(app.exec_())

下拉列表框QComboBox_第1张图片

你可能感兴趣的:(Pyqt5)