AttributeError:' int'对象没有属性' setText'

时间:2016-10-30 20:06:35

标签: python

我必须写一个射箭得分程序,我一直收到这个错误: AttributeError:' int'对象没有属性' setText'

def main():
    win = gameWindow()
    currentShot, overallScore = scoreOverlay(win)

    shot = 0
    totalScore = 0
    for i in range(5):
        p = win.getMouse()
        p.draw(win)
        x = p.getX
        y = p.getY
        score = scoring(p)

    currentShot.setText('Current Shot: {0:1}'.format(scoring))
    overallScore = 'overallScore' + 'currentShot'
    overallScore.setText('Total{0:1}'.format(overallScore))

    main()

任何想法如何解决这个问题?我不在这个问题上。 提前感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

下面; currentShot = 0在这里; overallScore = 0您将currentShot和overallScore设置为整数。它们不再分别等于Text(Point(175,13), 'Current Shot: ')Text(Point(175,340), 'Total: ')。为currentShot = 0overallScore = 0中的变量使用不同的变量名称,这应该可以解决您的错误