马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 zedi 于 2020-5-22 20:06 编辑 import pygame
import random
class Game:
def __init__(self):
pygame.init()
pygame.display.set_mode((800,600))
self.screen = pygame.time.Clock()
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
elif event.type == pygame.KEYDOWN:
self.keys = pygame.key.get_pressed()
elif event.type == pygame.KEYUP:
self.keys = pygame.key.get_pressed()
self.screen.fill((random.randint(0,255),random.randint(0,255),random.randint(0,255)))
pygame.display.update()
self.Clock.tick(60)
报错内容H:\SuperMario>F:/python牌神/python.exe h:/SuperMario/main.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "h:/SuperMario/main.py", line 11, in <module>
main()
File "h:/SuperMario/main.py", line 8, in main
game.run()
File "h:\SuperMario\source\tools.py", line 20, in run
self.screen.fill((random.randint(0,255),random.randint(0,255),random.randint(0,255)))
AttributeError: 'Clock' object has no attribute 'fill'
main的#游戏的主要入口
import pygame
from source import tools
def main():
game = tools.Game()
game.run()
if __name__ =='__main__':
main()
我找到原因了: self.screen = pygame.time.Clock() #Line 7
self.screen.fill((random.randint(0,255),random.randint(0,255),random.randint(0,255))) # Line 18
Clock 没有 fill 属性(方法)
|