首页 > 解决方案 > 我不知道我做错了什么,我已经按照指南进行操作,可能是过时的软件问题还是什么?

问题描述

请有人弄清楚为什么我很笨,这没有用,我不知道为什么会这样,请帮助:)

import pygame
import random

random1 = (random.randint(1, 2000))
random2 = (random.randint(1,2000))
width, height = random1, random2
fps = 60
red = (255, 0, 0)

window = pygame.display.set_mode((width, height))
pygame.display.set_caption("i don't know what im doing")

man_character = pygame.image.load('mancharacter.jpg')


def draw_window():
    window.fill(red)
    window.blit('mancharacter.jpg')
    window.blit('potato.PNG')
    pygame.display.update()

def main():
    clock = pygame.time.Clock()
    pizza = True
    while pizza:
        clock.tick(fps)
        for event in pygame.event.get():
            if event.type == pygame.Quit():
                pizza = False
        draw_window()
    pygame.Quit()

标签: pythonpygame

解决方案


看看这部分代码:

def main():
    #[...]
    for event in pygame.event.get():
        if event.type == pygame.Quit():
             pizza = False
        draw_window()
    pygame.Quit()

Pygame 没有任何属性“退出”,所以它应该有点像这样:

def main():
    #[...]
    while pizza:
        clock.tick(fps)
        for event in pygame.event.get():
            if event.type == pygame.QUIT: #Remove the parentheses and capitalise the word
                pizza = False
        draw_window()
    pygame.quit() #quit not Quit

这应该可以工作

import pygame
import random

random1 = (random.randint(1, 2000))
random2 = (random.randint(1,2000))
width, height = random1, random2
fps = 60
red = (255, 0, 0)

window = pygame.display.set_mode((width, height))
pygame.display.set_caption("i don't know what im doing")

man_character = pygame.image.load('mancharacter.jpg')


def draw_window():
    window.fill(red)
    window.blit('mancharacter.jpg')
    window.blit('potato.PNG')
    pygame.display.update()

def main():
    clock = pygame.time.Clock()
    pizza = True
    while pizza:
        clock.tick(fps)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pizza = False
        draw_window()
    pygame.quit()

main() #You need to call this function

推荐阅读