PyGame窗口没有打开,我也不知道为什么。我所知道的是"screen = display.set_mode(800,500)“是代码开始出现故障的行。以下是代码:
from pygame import *
from pygame.event import *
init()
screen = display.set_mode([800, 500])
RED = (255,0,0)
mousedown = False
while True:
for event in get():
if event.type == MOUSEBUTTONDOWN:
我试着用Pygame检测到一个USB游戏。每次我运行这段代码时,程序都会出现错误:第10行中的“program未初始化”。
import pygame as p
p.init()
stick = p.joystick.Joystick(0)
#get init returns always False
print("initialized:",bool(stick.get_init()))
#getting the name works as it should
print(stick.get_name())
#says always "pygame.error: J
所以这个问题对我来说有点奇怪。我编写了这段代码,看看玩偶游戏是否正确。
import pygame,sys
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400,300))
pygame.display.set_caption("Hello World")
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit(
有人能告诉我这段Python代码出了什么问题吗?我使用的是Python 3.8.2。 这段代码来自Python Crash Course,第二版:基于项目的编程入门。原始代码使用pygame.display.flip()而不是pygame.display.update(),原始代码将生成以下错误代码:pygame.error: Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface 然而,在我将其更改为pygame.display.update()后,它只是冻结了我的电脑与空白的Py
这周早些时候,我刚刚开始学习如何使用Pygame。在摆弄它的时候,我发现如果我做了一个全屏窗口,让它打开大约10秒,然后关闭它,我打开的所有其他窗口都会缩小,我的屏幕会在几秒钟内以较低的分辨率显示。 下面这段代码会发生这样的事情: import pygame
pygame.init()
pygame.display.set_mode((500, 500),
pygame.FULLSCREEN)
running = True
while running is True:
for event in pygame.event.get():
使用Python 2.7.2。当我尝试导入pygame时,我得到了这个错误信息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base imp
我希望这段代码表示嗨,当按下按钮时,我使用replit.com或repl.it,它表示为一个错误:
File "main.py", line 18, in intro
if keyboard.KEY_DOWN("a"):
TypeError: 'str' object is not callable
我正试图在python上做一个单倍游戏,但是像这样的错误不断出现。
import tkinter as tk
from tkinter import *
import os
import random
import math
import pyga
我一直在尝试让pygame模块在MacBook10.6上与python3兼容。我读到它很棘手,我不得不按照以下说明从源代码安装:一切正常,但当我尝试导入pygame时,我得到了这个错误:
Python 3.2.2 (v3.2.2:137e45f15c0b, Sep 3 2011, 17:28:59)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more inf
我一直收到错误:pygame.error: No available video device。这可以在python默认的空闲上工作,在Windows上安装python 3.10时会出现这种情况,但是对Replit(在线空闲)不起作用。
如您所见,我在Relpit中安装了pygame
我从代码的这一部分中得到了错误:
import pygame
import math
pygame.init()
WIDTH, HEIGHT = 800, 800
WIN = pygame.display.set_mode((WIDTH, HEIGHT)) <<<-- ERROR LINE
我使用python3和pygame,并且我有player类,其中我的player控件被定义为函数中的:
def get_input(self):
#xbox example code, which doesnt work:
buttons=pygame.joystick.Joystick.get_button()
if buttons(button=0):
self.jump()
#more code for xbox controller.
#keyboard, this wor
我最近开始用python编程,到目前为止我很喜欢它。我以前用c#和java编程,这可能导致了我的问题。在c#中,如果您有一个公共变量,它将在每个方法中更改。很抱歉给出了错误的解释,但是代码的可视化会更容易。
这段代码是我希望在c#格式的python中发生的一个例子。代码实际上不起作用,因为它只是一个例子。
class Player
{
public var player; //create the variable
public var playerRectangle;
public var playerMovement;
public Player()