简体   繁体   中英

Getting error when trying to interpolate variable

I can't seem to figure out what 'super' object has no attribute ' getattr ' means. I don't know why I am getting this error.

This is a simple guessing game, I am using Kivy for a GUI

import math
import kivy
kivy.require('1.11.0')
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.button import Button

class Layout(GridLayout):

    def __init__(self, **kwargs):
        super(Layout, self).__init__(**kwargs)

        self.cols = 3
        self.guesses = 10
        self.hasWon = False
        self.pressedStart = False
        self.ids.start.text = 'Start'
        self.ids.gameText.text = 'Press Start when have chosen your number and are ready!'
        self.ids.instructions.text = 'Choose any number between 0 and 20000 and I will guess it in 10 tries!'
        self.max_guess = 20000
        self.min_guess = 0
        self.guess = math.ceil((self.max_guess - self.min_guess) / 2)
        self.ids.guessText.text = f'Guess left: {self.guesses}'


    def higher(self):
        if self.pressedStart == True and self.hasWon == False:
            self.guesses -= 1
            self.min_guess += self.guess
            self.ids.startText.text = f'Is your number {self.guess}?'
        else:
            pass
    File "guessing_game.py", line 41, in higher
      self.ids.startText.text = f'Is your number {self.guess}?'
    File "kivy/properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
    AttributeError: 'super' object has no attribute '__getattr__'

Problem - AttributeError

  self.ids.startText.text = f'Is your number {self.guess}?'
File "kivy/properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'

Root cause

It means that the attribute or variable, ids.startText does not exist in either self.ids dictionary type property or object, Layout .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM