Error string index out of range

0

Good evening everyone!

I'm creating a calculator, but when it comes to finding the object that sent the signal to get the last character of the name to display on the lcd display, I get the above error. What am I missing?

import sys
from PyQt4 import QtGui


class Example(QtGui.QWidget):



  def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):

       self.termo = ""

       grid = QtGui.QGridLayout()
       self.setLayout(grid)

       self.lcd = QtGui.QLCDNumber(self) #cria o lcd
       grid.addWidget(self.lcd, 0,1)

       self.num1 = QtGui.QPushButton('1', self) #cria o botão 1, define sua 
                                                posição e conecta ao método  
                                                evtNumeros#
       grid.addWidget(self.num1, 1,1)
       self.num1.clicked.connect(self.evtNumeros)

       self.num2 = QtGui.QPushButton('2', self)
       grid.addWidget(self.num2, 1,2)
       self.num2.clicked.connect(self.evtNumeros)

       self.num3 = QtGui.QPushButton('3', self)
       grid.addWidget(self.num3, 1,3)
       self.num3.clicked.connect(self.evtNumeros)

       self.num4 = QtGui.QPushButton('4', self)
       grid.addWidget(self.num4, 2,1)
       self.num4.clicked.connect(self.evtNumeros)

       self.num5 = QtGui.QPushButton('5', self)
       grid.addWidget(self.num5, 2,2)
       self.num5.clicked.connect(self.evtNumeros)

       self.num6 = QtGui.QPushButton('6', self)
       grid.addWidget(self.num6, 2,3)
       self.num6.clicked.connect(self.evtNumeros)

       self.num7 = QtGui.QPushButton('7', self)
       grid.addWidget(self.num7, 3,1)
       self.num7.clicked.connect(self.evtNumeros)       

       self.num8 = QtGui.QPushButton('8', self)
       grid.addWidget(self.num8, 3,2)
       self.num8.clicked.connect(self.evtNumeros)

       self.num9 = QtGui.QPushButton('9', self)
       grid.addWidget(self.num9, 3,3)
       self.num9.clicked.connect(self.evtNumeros) 

       self.num0= QtGui.QPushButton('0', self)
       grid.addWidget(self.num0, 4,1)
       self.num0.clicked.connect(self.evtNumeros) 

       mais= QtGui.QPushButton('+', self)
       grid.addWidget(mais, 4,2)
       menos= QtGui.QPushButton('-', self)
       grid.addWidget(menos, 4,3)
       vezes= QtGui.QPushButton('*', self)
       grid.addWidget(vezes, 5,1)
       dividir= QtGui.QPushButton('/', self)
       grid.addWidget(dividir, 5,2)
       igual= QtGui.QPushButton('=', self)
       grid.addWidget(igual, 5,3)

       self.setWindowTitle('Calculadora')
       self.show()



    def evtNumeros(self):      #Metodo responsavel por pegar o ultimo caractere 
                               do nome do obeto que emitiu o sinal e mostrá-lo 
                               no visor lcd#

       self.termo += self.sender().objectName()[-1]
       self.lcd.display((self.termo))   

def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
    
asked by anonymous 14.08.2018 / 23:48

0 answers