PyQt5-键盘输入校验

发布时间:2024年01月17日

校验键盘输入的每一个字符:
示例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

文章来源:https://blog.csdn.net/www_djh/article/details/135643549
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。