我可以在不隐藏标题栏的情况下最大化 pygame 窗口吗?

问题描述 投票:0回答:1

我目前正在用pygame编写一个小游戏。有什么方法可以将 pygame 窗口设置为屏幕的最大尺寸,但仍然可以通过标题栏关闭窗口?我想让整个东西非常动态,所以要适应显示器的显示尺寸

我已经尝试过 pygame.display.set_mod() 方法并将 pygame.FULLSCREEN 作为参数传递。但是我那里没有标题栏了。

python pygame fullscreen titlebar
1个回答
0
投票

将标题栏保留在窗口中的最简单方法之一是使用 Tkinter。 Tkinter 是一个预装在 Python 中的模块,它可以为您提供正在使用的屏幕大小,您可以将其放入 pygame 函数中。

你可以这样使用它:

import pygame
import tkinter

root = tkinter.Tk()
width = root.winfo_screenwidth()
height = root.winfo_screenheight()

pygame.init()

# Set size of window
screen = pygame.display.set_mode([width, height])

done = False
while done == False:
    # Check for closing of window
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
    screen.fill((255, 255, 255))

pygame.quit()
© www.soinside.com 2019 - 2024. All rights reserved.