校验键盘输入的每一个字符:
示例1:
@QtCore.pyqtSlot(int)
def on_keyPressEvent(self, keyEvent:QtCore.QEvent):
keyValue=keyEvent.key()
if keyValue == Qt.Key.Key_Escape: # 按下Esc键时关闭self
self.close()
elif keyValue >= ord('A') and keyValue <= ord('Z'): # 只接收大写字母作为有效输入
char = chr(keyValue).upper()
print("Valid input character: ", char)
else:
pass
参考了:
https://blog.csdn.net/Dream_Gao1989/article/details/123440771?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170545931216800182197042%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=170545931216800182197042&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogfirst_rank_ecpm_v1~rank_v31_ecpm-1-123440771-null-null.nonecase&utm_term=match&spm=1018.2226.3001.4450