微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使我的 pygame 窗口可调整大小

如何解决如何使我的 pygame 窗口可调整大小

import pygame
import sys
from pygame import *

WINDOW_SIZE = (900,700)
screen = pygame.display.set_mode(WINDOW_SIZE,32)
pygame.display.set_caption('Pygame Program')
pygame.display.set_icon(pygame.image.load('spaceship (3).png'))


player_img = pygame.image.load('ClipartKey_738895_adobespark.png')
player_X = 130
player_Y = 600
moving_right=False
moving_left=False

if moving_right:
    player_X+=0.3
if moving_left:
    player_X-=0.3


def player():
    screen.blit(player_img,(player_X,player_Y))


running = True
while running:


    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            sys.exit()


        if event.type==KEYDOWN:
            if event.key==K_RIGHT:
                moving_right=True
            if event.key==K_LEFT:
                moving_left=True
        if event.type==KEYUP:
            if event.key==K_RIGHT:
                moving_right=False
            if event.key==K_LEFT:
                moving_left=False


    screen.fill((0,200,255))


    player()
    if player_X<=2:
        player_X+=3


    pygame.display.update()

这是我的代码。 我想让窗口像 Windows 中的所有其他应用程序一样可调整大小。 我试过 pygame.display.toggle_fullscreen() 但它不起作用。它没有显示任何错误,但会发出警告并说在 toggle_fullscreen 中重新创建窗口,然后挂起。 请告诉我如何修复它。

解决方法

只需更改行

screen = pygame.display.set_mode(WINDOW_SIZE,32)

from pygame.locals import RESIZABLE
screen = pygame.display.set_mode(WINDOW_SIZE,RESIZABLE,32)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。