You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Pygame开发Python游戏时遇AttributeError:'tuple'对象无tick属性求助

解决Pygame中AttributeError: 'tuple' object has no attribute 'tick'的问题

错误根源在这一行代码:

clock = pygame,time.process_time()

这里的逗号会把pygame模块和time.process_time()的返回值打包成一个元组,而元组并没有tick方法。Pygame中实现帧率控制的正确方式是创建pygame.time.Clock()对象。

修正后的完整代码:

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()  # 正确的时钟对象创建方式
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()

内容的提问来源于stack exchange,提问作者Shejal Pal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 03:52:02