python - 我不知道我做错了什么,我已经按照指南进行操作,可能是过时的软件问题还是什么?
问题描述
请有人弄清楚为什么我很笨,这没有用,我不知道为什么会这样,请帮助:)
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()
解决方案
看看这部分代码:
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
推荐阅读
- php - 从 Route 获取值
- python - 如何在 Synology NAS 上安装 GEOS(或 libgeos)?
- node.js - 公司用户和员工用户之间的关系
- javascript - sidequestion - 在退出按钮上暂停视频(退出全屏)
- elasticsearch - Elasticsearch 集群的只读副本
- java - Jasypt 休眠 5 支持?
- angular - Angular 7:通过路由器访问组件方法
- linux - Linux Bash 脚本日期
- android - 如何在 Xamarin 中实现 Google Play 应用内更新和使用 Play 核心库
- apache-kafka - 如何在 Quarkus 中注入 KafkaTemplate