2 hmh2 yy HMH2_YY 于 2017.09.16 23:29 提问

请各位大佬帮看看问题出在哪里~~使用PyQt的设计师 信号与槽不响应

点击 “求解”按钮之后,为什么不输出结果? connect()函数不是已经连接了要响应的函数了吗?

图片说明

#!/usr/bin/python3

-*- coding: UTF-8 -*-

from PyQt5.QtWidgets import QWidget,QApplication
from PyQt5 import uic
from qua_rc import Ui_MainWindow
import sys
import numpy

#qtCreatorFile = "qua.ui"
#Ui_MainWindow,QtBaseClass = uic.loadUiType(qtCreatorFile)

class MyWindow(QWidget,Ui_MainWindow):
def init(self):
super(MyWindow,self).__init__()
self.setupUi(self)

    self.calc_qua_button.clicked.connect(self.quadretic)

def quadretic(self):
    a = self.a_box.toPlainText().toDouble()
    b = self.b_box.toPlainText().toDouble()
    c = self.c_box.toPlainText().toDouble()
    p = numpy.poly1d([a, b, c])
    L = p.r
    self.result1_window.setText(str(L[0]))
    self.result1_window.setText(str(L[1]))

if name == '__main__':
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())

2个回答

dzb3688
dzb3688   2017.09.22 15:41
已采纳

Hello, 你百度发的私信为何回复不了?
你上面的代码有问题
问题1:
获取QlineEdit值用:QLineEdit.text(),
获取QTextEdit值用:QTextEdit.toPlainText()
问题2:
QlineEdit没有toDouble方法
问题3:
一元二次方程接收两个值的text,你只给result1赋值了,你让result2 怎么想

修改代码如下:

 #!/usr/bin/python3
# -*- coding: UTF-8 -*-
from PyQt5.QtWidgets import QWidget,QMainWindow,QApplication
from PyQt5 import uic
from qua_rc import Ui_MainWindow
import sys
import numpy
#qtCreatorFile = "qua.ui"
#Ui_MainWindow,QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyWindow(QWidget,Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.calc_qua_button.clicked. connect(self.quadretic)

    def quadretic(self):
        a = self.a_box.text()
        b = self.b_box.text()
        c = self.c_box.text()
        p = numpy.poly1d([a, b, c])
        L = p.r
        self.result1_window.setText(str(L[0]))
        self.result2_window.setText(str(L[1]))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())

执行结果:
图片说明

devmiao
devmiao   Ds   Rxr 2017.09.17 22:55
Csdn user default icon
上传中...
上传图片
插入图片