0

I'm implementing a code that shows up an image in fullscreen size, using PyGame. I have two screens in my setup, one monitor and the one of the laptop. When I run my code to show on the monitor all works fine, but when I try it on the laptop screen something crash, and only a black screen is shown. My code is as follows:

def open_window2(path, key):
    # key dict
    key_dict={'a':K_a, 'b':K_b, 'c':K_c, 'd':K_d, 'e':K_e, 'f':K_f,
              'g':K_g, 'h':K_h, 'i':K_i, 'j':K_j, 'k':K_k, 'l':K_l,
              'm':K_m, 'n':K_n, 'o':K_o, 'p':K_p, 'q':K_q, 'r':K_r,
              's':K_s, 't':K_t, 'u':K_u, 'v':K_v, 'w':K_w, 'x':K_x,
              'y':K_y, 'z':K_z}
    
    pygame.init()

    # get screen resolution
    resolution = (pygame.display.Info().current_w, pygame.display.Info().current_h)

    surface = pygame.display.set_mode(resolution, FULLSCREEN)
    
    image = pygame.image.load(path)
    image = pygame.transform.scale(image, resolution)
    
    rect = image.get_rect(); rect.center = resolution[0]//2, resolution[1]//2
    
    surface.blit(image, rect)
    pygame.display.update()

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN: #press-key events
                if event.key == key_dict[key]: # if C key is pressed ...
                    running = False
    pygame.quit()

When I set it to pygame.FULLSCREEN shows a black screen, but when I set it to pygame.RESIZABLE the image is shown.

What should I do to fix the black screen problem?

Luan Souza
  • 159
  • 1
  • 1
  • 11
  • Why do you think the problem is related to your code? It works on one screen, but doesn't work on the other, therefore the problem is related to system. Did updatet the graphics driver of the integrated graphic card? Do you have a dedicated graphic card? – Rabbid76 Aug 10 '21 at 18:28
  • @Rabbid76 my system is updated. The problem also occurs in another laptop. The additional line "pygame.display.update()" inside the loop was put just for test, which I've already removed from the above code... – Luan Souza Aug 10 '21 at 18:57
  • What part of the code should I fix then? – Luan Souza Aug 10 '21 at 19:18
  • You can't fix it. What you're trying to do is impossible (with pygame). You cannot run 2 pygame windows in 1 application. See [Pygame with Multiple Windows](https://stackoverflow.com/questions/29811814/pygame-with-multiple-windows) – Rabbid76 Aug 10 '21 at 19:21
  • Can you purpose a solution to plot an image in full screen and stop the execution whenever the user wants? – Luan Souza Aug 10 '21 at 19:38

1 Answers1

0

I've found a solution. I don't know how pyglet.FULLSCREEN flag works but there is another way to do that without using it. You can just join two flags, pyglet.SCALED and pyglet.NOFRAME and it should work well.

surface = pygame.display.set_mode(resolution, pygame.SCALED|pygame.NOFRAME).

pygame.SCALED refers to adjust to the fullscreen mode, and pygame.NOFRAME removes bars and other showing parts.

It will plot the image you want on the entire screen, without showing bars, menus, etc.

Luan Souza
  • 159
  • 1
  • 1
  • 11