from PyQt5.Qt import *
from untitled import Ui_Form
class Window(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.setWindowTitle("的学习")
self.setFocus()
self.lineEdit.installEventFilter(self)
self.lineEdit_2.installEventFilter(self)
def eventFilter(self, a0: 'QObject', a1: 'QEvent') -> bool:
'''
:param a0: 对象属性名
:param a1: 事件类型
:return:
'''
if (a0 is self.lineEdit and a1.type()==QEvent.KeyPress and a1.key()==16777220):
self.label.setText('输入完成'+self.lineEdit.text())
if a0 is self.lineEdit_2 and a1.type()==QEvent.KeyPress and a1.key()==16777220:
self.label_2.setText('输入完成'+self.lineEdit_2.text())
return super(Window,self).eventFilter(a0,a1) #不能漏掉,不然会闪退
if __name__ == '__main__':
import sys
app=QApplication(sys.argv)
win=Window()
win.show()
sys.exit(app.exec_())
03-07
1174
06-06
357