pygame中的全屏模式是全黑的

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

我对pygame的全屏选项有一些问题。这是一些简单地绘制蓝色窗口的代码,通过按R我们可以在蓝色和紫色之间切换。然后,我们还可以使用FG在全屏模式和窗口模式之间切换。 F是显式实现的,G使用方法toggle_fullscreen()

toggle_fullscreen()

我在使用Python 3.6.8的Ubuntu 18.04上。这是我的观察结果:

  1. 使用pygame 2.0.0.dev6,当使用FG全屏显示时,屏幕将执行以下操作:
    1. 闪烁几次
    2. 作为最小化图标进入任务栏
    3. 如果我单击图标,屏幕会再闪烁几次,最后我们全屏显示
    4. 问题:屏幕为黑色,按钮R进行not翻转颜色(但打印消息)
  2. 仍然使用pygame 2.0.0.dev6。在这种情况下,GF按钮的行为有所不同:当从全屏返回到带有[[G的窗口时,R按钮不会翻转颜色,即使在窗口版本。当使用F时,它可以工作。
  3. 对于pygame版本2.0.0.dev3,
  4. G
  5. 按钮根本不起作用,而F具有与以前相同的行为。
我的主要问题是1.4 。:全屏模式为全黑。

现在让我们进行修改。更改

F

按钮的代码中的以下行import pygame, sys from pygame.locals import * #Initializes pygame pygame.init() #Defines the Clock object clock = pygame.time.Clock() #Just draws a blue screen size = (960, 540) blue = (0,0,100) purp = (100,0,100) is_blue = True display_surf = pygame.display.set_mode(size, RESIZABLE) display_surf.fill(blue) mainLoop = True is_fullscreen = False #Mainloop while mainLoop: dt = clock.tick(12) for event in pygame.event.get(): if event.type == pygame.QUIT: mainLoop = False if event.type == pygame.KEYDOWN: #Single key pressed if event.key == K_f: #Toggles fullscreen is_fullscreen = not is_fullscreen old_surface = display_surf setmode = FULLSCREEN if is_fullscreen else RESIZABLE display_surf = pygame.display.set_mode(size, setmode) display_surf.blit(old_surface, (0,0)) del old_surface if event.key == K_q: #Quits the app mainLoop = False if event.key == K_r: #Redraws the blue or purple print("Trying to flip colors") display_surf.fill(purp if is_blue else blue) is_blue = not is_blue if event.key == K_g: #Toggles fullscreen with the dedicated method is_fullscreen = not is_fullscreen pygame.display.toggle_fullscreen() pygame.display.update() pygame.quit()
这将以当前的屏幕分辨率进入全屏显示,而不是我在顶部指定的分辨率。现在的问题是1.1。,1.2和1.3。不见了:该应用立即进入全屏模式。但是问题1.4。仍然存在,并且该程序不再接受输入。如果按

Q

,它不会退出。它不需要Alt + TabAlt + F4,所以我必须重新启动计算机。
python pygame fullscreen
1个回答
1
投票
setmode = FULLSCREEN|SCALED if is_fullscreen else RESIZABLE #FULLSCREEN -> FULLSCREEN|SCALED 创建一个pygame.display.set_mode对象,该对象与窗口关联。当再次调用pygame.display.set_mode时,之前与该表面关联的对象将失效。

您必须pygame.Surface“旧”表面:

pygame.Surface

© www.soinside.com 2019 - 2024. All rights reserved.