元组对象没有属性勾选

问题描述 投票:0回答:3

我正在通过查看一些教程用 python 制作游戏,但遇到了一些错误 下面是代码:

import pygame
import time
pygame.init()
WIDTH, HEIGHT = 800, 500
pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Word Mystery!")

FPS = 60
clock = pygame,time.process_time()
run = True

while run:
  clock.tick(FPS)
    
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      run = False
    if event.type == pygame.MOUSEBUTTONDOWN:
      pos = pygame.mouse.get_pos()
      print(pos)


pygame.quit()

下面是我收到的错误:

Traceback (most recent call last):
  File "/home/runner/hangman/main.py", line 13, in <module>
    clock.tick(FPS)
AttributeError: 'tuple' object has no attribute 'tick'
exit status 1

请有人解决这个错误

python pygame attributeerror
3个回答
0
投票

更改逗号:

clock = pygame.time.process_time()
#             ^

0
投票
this one correct code

import pygame
import time

pygame.init()
WIDTH, HEIGHT = 800, 500
pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Word Mystery!")

FPS = 60
clock = pygame.time.Clock()  # Corrected this line

run = True

while run:
   clock.tick(FPS)

    for event in pygame.event.get():
       if event.type == pygame.QUIT:
           run = False
       if event.type == pygame.MOUSEBUTTONDOWN:
          pos = pygame.mouse.get_pos()
          print(pos)

 pygame.quit()

0
投票

在代码中将

clock = pygame,time.process_time()
替换为
clock = pygame.time.Clock()
,它应该可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.