当前位置: 首页 > 知识库问答 >
问题:

Time Module 在 Pycharm 中不起作用(我使用的是 Python 3.8.5,Pycharm

经伟
2023-03-14

我正在尝试用Python3编写我的第一个游戏

当我运行代码时,我收到以下错误:

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/TechSlugz/PycharmProjects/Pong-Project/Pong1.py", line 7, in <module>
    clock = pygame.time.clock()
AttributeError: module 'pygame.time' has no attribute 'clock'

Process finished with exit code 1

代码只是游戏窗口的基本设置,看看吧

import pygame
import sys

# General Setup

pygame.init()
clock = pygame.time.clock()

# Setting Up The Main Window

screen_width = 1280
screen_height = 960
screen = pygame.display.setmode((screen_width, screen_height))
pygame.display.set_caption("Pong")

while True:
    #handling input
    for event in pygame.event.get():
        if event.type == pygame.quit:
            pygame.quit()
            sys.exit()

#Updating The Window

pygame.display.flip()
clock.tick(60)

你能注意到我在这个问题上做错了什么吗?我的想法中没有一个认为时间是一个pygame模块,但是我非常确定它是...

共有1个答案

时衡虑
2023-03-14

时钟是一个类,所以应该使用C而不是C。

< code > clock = py game . time . clock()

你还有另一个问题,< code>setmode不是一个可用的函数。你想写< code>set_mode

适合我的代码:

import pygame
import sys

# General Setup
pygame.init()

clock = pygame.time.Clock()

# Setting Up The Main Window

screen_width = 1280
screen_height = 960
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Pong")

while True:
    #handling input
    for event in pygame.event.get():
        if event.type == pygame.quit:
            pygame.quit()
            sys.exit()

#Updating The Window

pygame.display.flip()
clock.tick(60)
 类似资料:
  • 问题内容: 我正在使用Mac OS X并尝试设置pycallgraph。 香港专业教育学院安装pycallgraph与pip和graphviz与自制。 一切都可以从Shell进行。但不是来自pycharm。 此处: -> virtualenv目录 ->项目目录 它要我做什么? 问题答案: 答案是: 在菜单栏中: -> -> 在对话框中: 对于所选文件或对于默认值/ Python: 环境字段组: >

  • 下面是我用raspberry PI的python(Thonny Idle)编写的代码。 请忽略Url,它不是真实地址。密码 错误 回溯(最近一次呼叫最后一次): 文件“/home/pi/Documents/PythonCode/TestingFirebase-1.py”,第17行,在 文件“/usr/local/lib/python3.7/dist-packages/firebase/decora

  • 问题内容: 在调试pycharm中的代码时,按Ctrl + C时,我的python try / except循环似乎不会触发键盘中断。我的代码如下所示: 编辑: 我的精简代码工作似乎出现了一些问题,并且没有产生相同的错误。完整的代码可以在这里查看。我还重新整理了代码(上面的代码),并产生了相同的错误。 问题答案: 从屏幕截图中可以看出,您正在IDE中运行此代码。关于IDE的问题是,它们与正常运行并

  • 我正在尝试使用tomahawk的selectManyCheckbox,但它不起作用,我在我的web应用程序中收到以下消息: 警告:页面 /resources/components/tabs/abaEdicaoFuncoesFuncionario.xhtml声明命名空间http://myfaces.apache.org/tomahawk并使用标记t: selectManyCheckbox,但没有与命