pyqt5(3)-comboBox-lineEdit-checkBox控件的使用

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
     def __init__(self, parent=None):     #
        super(MainWindow,self).__init__(parent)
        self.setupUi(self)
        self.SetLineEdit() # 1.
        self.SetComboBox() #
     #   self.getCheckBox_state()# 获取是否被选
     #   self.getCheckBox_text() # 获取文本
         #self.lineEdit.textChanged.connect(self.LineEditTextShow)
     def _emitLineEditTextShow(self):
         print("LineEditTextShow")
         m_linetext = self.lineEdit.text()
         print(m_linetext)
     def SetLineEdit(self):
         print("SetLineEdit")
         self.lineEdit.textChanged.connect(self._emitLineEditTextShow)   #更改后响应函数
         self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)       # 设置成密码模式
         self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.PasswordEchoOnEdit)  # 编辑的时候可以看到
         self.lineEdit_2.setValidator(QtGui.QIntValidator(10000000, 99999999))  # 设置8位整数

     def getCheckBox_state(self):
         print("getCheckBox_state")
         self.checkBox.stateChanged.connect(self._emitCheckBox)
         self.checkBox_2.stateChanged.connect(self._emitCheckBox)
     def getCheckBox_text(self):
         print("getCheckBox_text")
         oper = ''
         if self.checkBox.isChecked():
             oper += '\n' + self.checkBox.text()
         if self.checkBox_2.isChecked():
             oper += '\n' + self.checkBox_2.text()
         print(oper)
         #QMessageBox.information(MainWindow, '提示', '\n' + oper + '登陆', QMessageBox.Ok)
       
     def _emitCheckBox(self):
         print("CheckBox")
         choice_1 = self.checkBox.text() if self.checkBox.isChecked() else ''
         choice_2 = self.checkBox_2.text() if self.checkBox_2.isChecked() else ''
     def SetComboBox(self):
         print("SetComboBox")
         self.comboBox_1.currentIndexChanged.connect(self._emitComboBox1)
         self.comboBox_2.currentIndexChanged.connect(self._emitComboBox2)
     def _emitComboBox1(self):
         self.label_COMB1.setText(self.comboBox_1.currentText())
     def _emitComboBox2(self):
         self.label_COMB2.setText(self.comboBox_2.currentText())



# Press the green button in the gutter to run the script.
import sys
if __name__ == '__main__':

    app = QtWidgets.QApplication(sys.argv)
    mainWindow = MainWindow()
    mainWindow.show()
    sys.exit(app.exec_())

1.combobox控件
 

#combobox 
方法:
addItem()      添加item
addItems()
count()        所有选项的数量
currentText()  当前选项的文本
cunrrentIndex()当期选项的索引
itemText()     获取所有为index的文本
setItemText()  根据索引设置文本
clear()        清除所有的选项

信号:
activated
currentIndexChanged

#1.增加的选项+槽函数
list=['董事长','总经理','人事','员工']
self.comboBox.addItems(list)
self.comboBox.currentIndexChanged.connect(self.funlist)



def funlist(self):
   self.showinfo()

def showinfo(self):
    value="你所选择职位为:"+self.comboBox.currentText()
    self.label.setText(vaule)


2.lineEdit
 

常用的方法:
setFocus() 获取焦点
text()     获取值
setText()  设置值
setEchoMode() 设置属性 密码
setInPutMask()  设置掩码属性 
setPlaceholderText() 设置文本框文字
setReadOnly()      只读属性
setAlignment()
setMaxLength()
setReadOnly()
setValidator()   限制输入:整数 正则表达式
clear()  清除

信号:
textChaned
editingFinished


3.checkbox
 

#1.3种状态
QT.PartiallyChecked
QT.Checked
QT.Unchecked

#3.信号触发器
self.checkBox.clicked(self.get_value)



#2.设置槽函数


def get_value(self):
   oper=''
   if  self.checkBox.isChecked():
         oper +='\n'+self.checkBox.text()
   if  self.checkBox_2.isChecked():
         oper +='\n'+self.checkBox_2.text()
   if  self.checkBox_3.isChecked():
         oper +='\n'+self.checkBox_3.text()
   print(oper)

   QMessageBox.information(MainWindow,'提示','你选择的权限如下:\n'+oper +'登陆',QMessageBox.OK)


 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值