我正在做一个心算训练师。我开始掌握 PyQT5。
在程序中,需要显示两个随机数的乘积,并输入相乘的结果。
如何在没有界面的情况下使其清晰。我不知道如何print
在 PyQT5 的输出字段中显示。
main.py文件中的这段代码:
import sys,random
from PyQt5 import QtCore, QtGui, QtWidgets
from Ui_TestGUI2_3 import Ui_TestGUI2
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
TestGUI2 = QtWidgets.QMainWindow()
ui = Ui_TestGUI2()
ui.setupUi(TestGUI2)
TestGUI2.show()
sys.exit(app.exec_())
def Qcount(self):
a=random.randrange(-100,100)
b=random.randrange(-100,100)
print(a,"*",b)#Этот принт вывести на lineEdit1
d=int(input())
if d==a*b:
print("Все верно")
应该使用什么方法来打印输出?
这部分在Ui_TestGUI2_3.py中(由Qt Designer创建)
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_TestGUI2(object):
def setupUi(self, TestGUI2):
TestGUI2.setObjectName("TestGUI2")
TestGUI2.resize(387, 315)
self.centralwidget = QtWidgets.QWidget(TestGUI2)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(110, 130, 158, 23))
self.pushButton.setObjectName("pushButton")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(110, 30, 161, 41))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(110, 80, 161, 41))
self.lineEdit_2.setObjectName("lineEdit_2")
TestGUI2.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(TestGUI2)
self.menubar.setGeometry(QtCore.QRect(0, 0, 387, 21))
self.menubar.setObjectName("menubar")
TestGUI2.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(TestGUI2)
self.statusbar.setObjectName("statusbar")
TestGUI2.setStatusBar(self.statusbar)
self.retranslateUi(TestGUI2)
QtCore.QMetaObject.connectSlotsByName(TestGUI2)
def retranslateUi(self, TestGUI2):
_translate = QtCore.QCoreApplication.translate
TestGUI2.setWindowTitle(_translate("TestGUI2", "TestGUI2"))
self.pushButton.setText(_translate("TestGUI2", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
TestGUI2 = QtWidgets.QMainWindow()
ui = Ui_TestGUI2()
ui.setupUi(TestGUI2)
TestGUI2.show()
sys.exit(app.exec_())
更新:
主文件
ui_TestGUI2_3.py