【问题标题】:Is there a way to completely prevent the user form exiting the pygame window?有没有办法完全阻止用户表单退出 pygame 窗口?
【发布时间】:2020-11-10 04:10:08
【问题描述】:

我想完全阻止用户关闭除键 x 之外的 Pygame 窗口。目前,我能够阻止用户关闭它,但我无法阻止用户打开另一个与其重叠的窗口(按 windows 键 -> 打开与 Pygame 窗口重叠的 chrome)。

import sys
import pygame
from pygame.locals import *
pygame.init()
infoObject = pygame.display.Info()
screen = pygame.display.set_mode((infoObject.current_w, infoObject.current_h), flags=pygame.NOFRAME)
while True:
    screen.fill((0, 0, 0))
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_x:
                pygame.quit()
                sys.exit()
        if event.type == QUIT:
            pass
    pygame.display.flip()

【问题讨论】:

  • 我认为没有办法做到这一点,因为您可以使用 Overlay2 等软件绕过任何窗口覆盖,甚至只是第二个监视器。此外,某些防病毒软件(例如 AVG)有时会将不允许关闭的软件视为病毒。

标签: python pygame


【解决方案1】:

对于这项任务,我们没有完整的解决方案。

您可以通过将显示模式设置为 NOFRAME 来使标题变量消失(您已经使用过这个):pygame.display.set_mode(flags = pygame.NOFRAME),但这对于仅停止关闭按钮来说是多余的

尽管任何计算机知识最低的用户都会启动任务管理器并杀死python.exe :-(

有一些方法可以通过 Windows 中的注册表、图像文件执行选项等等来禁用任务管理器,但是你的游戏脚本将几乎无法以管理员权限运行(使用 UAC 的唠叨)

【讨论】:

    【解决方案2】:

    为此,您可以将这段代码添加到您的pygame.display.set_mode()pygame.display.set_mode(..., flags=pygame.NOFRAME)。现在,带有“x”按钮的栏将消失。

    请注意,如果您决定进行此更改,您将无法再移动游戏窗口。 (除非你改回来)。

    【讨论】:

      猜你喜欢
      • 2012-04-18
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 2021-04-11
      • 1970-01-01
      相关资源
      最近更新 更多