使用python3+pycham编写简易计算器出现AttributeError: 'QPushButton' object has no attribute 'cliked',有没有大神指教

# _*_ coding:utf-8 _*_  //
from PyQt5.QtGui import *
from PyQt5.Qt import *
from PyQt5.QtCore import *
import sys, math, string


class Calculator (QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.initUI()
        self.last = []

    def initUI(self):
        list = ['%', '**', 'sqrt', 'C', 7, 8, 9, '+', 4, 5, 6, '-', 1, 2, 3, '*', 0, '.', '=', '/']
        length = len(list)
        #动态创建按钮
        for i in range(length):
            self.button = QPushButton(str(list[i]), self)
            #将按钮的clicked信号与onButtonClick函数连接
            self.button.cliked.connect(self.onButtonClick)
            x = i % 4
            y = int(i / 4)
            self.button.move(x * 40 + 10, y * 40 + 100)
            self.button.resize(30, 30)
        #创建文本框
        self.lineEdit = QLineEdit('', self)
        self.lineEdit.move(10, 10)
        self.lineEdit.resize(150, 70)
        self.setGeometry(200, 170, 300)
        self.setWindowTitle('计算器')
        self.show()

    def onButtonClick(self):
        t = self.lineEdit.text()                    #获取文本框文本
        new = self.sender().text()                  #获取按钮显示文本
        self.last.append(new)
        print(self.last)
        self.lineEdit.setText(t + new)              #设置文本框文本
        if new == '=':                              #等号按钮
            result = eval(str(t))                   #计算
            self.lineEdit.setText(str(result))      #显示计算结果
        if new == 'C':                              #清空按钮
            self.lineEdit.setText('')
        if new == 'sqrt':                           #开方按钮
            self.lineEdit.setText('')
            result = math.sqrt(string.atof(t))
            self.lineEdit.setText(str(result))
        if new == '**':                              #乘方按钮
            self.lineEdit.setText('')
            result = string.atof(t) ** 2
            self.lineEdit.setText(str(result))


app = QApplication(sys.argv)
w = Calculator()
w.show()
sys.exit(app.exec_())

请问怎么解决AttributeError: ‘QPushButton’ object has no attribute ‘cliked’。
使用python3+pycham编写简易计算器出现AttributeError: 'QPushButton' object has no attribute 'cliked',有没有大神指教_第1张图片

你可能感兴趣的:(使用python3+pycham编写简易计算器出现AttributeError: 'QPushButton' object has no attribute 'cliked',有没有大神指教)