相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have to write an archery scoring program and I keep getting this error: AttributeError: 'int' object has no attribute '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()

Any ideas how to fix this? I am out of my depth on this one. Thank you in advance for any help you may be able to provide.

Here; currentShot = 0 and here; overallScore = 0 you are setting currentShot and overallScore as integers. They are no longer equal to Text(Point(175,13), 'Current Shot: ') and Text(Point(175,340), 'Total: ') respectively. Use different variable names for the variables in currentShot = 0 and overallScore = 0 and that should fix your error

That worked thank you, I ran into another problem after that and fixed it, and now have run into another. Now I get TypeError: non-empty format string passed to object.__format__ – J. Adams Oct 30, 2016 at 20:59 If I'm following your code correctly, you need to change currentShot.setText('Current Shot: {0:1}'.format(scoring)) to currentShot.setText('Current Shot: {0:1}'.format(shot)) or currentShot.setText('Current Shot: {0:1}'.format(score)). (I'm not sure whether it's the shot or score variable you wish to use here, but either one it should also be converted to a string, for example score = str(scoring(p))) That is because here you are attempting to format a function, scoring(), and rather should be formatting a string. – Eric Oct 31, 2016 at 19:11 Also, overallScore = 'overallScore' + 'currentShot' should be update to reflect your new variable names, overallScore = shot + totalScore – Eric Oct 31, 2016 at 19:13 Sorry, that should be totalScore = shot + totalScore, and the next line overallScore.setText('Total{0:1}'.format(overallScore)) should also be updated as overallScore.setText('Total{0:1}'.format(totalScore))... I hope this helps, I'm not entirely sure the end-goal of this script so I'm mostly shooting in the dark – Eric Oct 31, 2016 at 19:15

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章