Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

python - keyPressEvent not printing when clicking button in Calculator UI PySide2

I am beginner and following a course on Python GUIs. This time he is teaching a GUI done on QT designer and then translated to python code using PySide. The problem is that the event is not printed if I click one button.

Link to see translated PySide2 ui_calculadora.py below: https://drive.google.com/file/d/1G3xXnz1WBSdns8gLkFNwcwAkwZXdOqrL/view?usp=sharing

import sys
from PySide2.QtWidgets import *
from VISTA.ui_calculadora import Ui_Calculadora
 
 
class Calculadora(QDialog):
    
    def __init__(self):
        super(Calculadora, self).__init__()
        self.calculadora = Ui_Calculadora()
        self.calculadora.setupUi(self)
    
    def keyPressEvent(self, event):
        print('Key: ' + str(event.key()) + ' | Text Press: ' + str(event.text()))
 
 
if __name__ == "__main__":
    print("----Example Starts----")
 
    app = QApplication(sys.argv)
    mi_aplicacion = Calculadora()
    mi_aplicacion.show()
    sys.exit(app.exec_())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...