I'm working through a python book. So far, all of the programs have worked, but now I'm stuck. I typed in the program, and I'm getting this error when I run it. I checked all of the lines several times, and I think everything's right. It is supposed to open a text window and 10 seconds later show a game character. I'm Using Python 3.8.10 On Windows 10 Pro 64-bit and this is the error: AttributeError: 'DynamicText' object has no attribute 'draw' and here is the code:
import pygame
import time
import subprocess
pygame.init()
screen = pygame.display.set_mode((800, 250))
clock = pygame.time.Clock()
font = pygame.font.Font(None, 25)
pygame.time.set_timer(pygame.USEREVENT, 200)
def text_generator(text):
tmp = ""
for letter in text:
tmp += letter
if letter != " ":
yield tmp
class DynamicText(object):
def __init__(self, font, text, pos, autoreset=False):
self.done = False
self.font = font
self.text = text
self._gen = text_generator(self.text)
self.pos = pos
self.autoreset = autoreset
self.update()
def reset(self):
self._gen = text_generator(self.text)
self.done = False
self.update()
def update(self):
if not self.done:
try: self.rendered = self.font.render(next(self._gen), True, (0, 128, 0))
except StopIteration:
self.done = True
time.sleep(10)
subprocess.Popen("python C:\\Users\\david\\Documents\\pythonbook\\pygame1.py 1", shell=True)
def draw(self, screen):
screen.blit(self.rendered, self.pos)
text=("Steve has gone on a quest to defeat the Ender Dragon. Will he make it?")
message = DynamicText(font, text, (65, 120), autoreset=True)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT: break
if event.type == pygame.USEREVENT: message.update()
else:
screen.fill(pygame.color.Color('black'))
message.draw(screen)
pygame.display.flip()
clock.tick(60)
continue
break
pygame.quit()
How can I figure out what the error message means? Or does anyone know?