简体   繁体   中英

Pygame window won't show up in Jupyter

I'm currently trying to program a tiny pygame game in a Jupyter notebook from a CoCalc project. As a first test, I just tried to display a window with this piece of code:

import pygame

background_colour = (255,255,255) 
(width, height) = (300, 200)

screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Tutorial 1')
screen.fill(background_colour)

pygame.display.flip()

running = True
while running:
  
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = False
      pygame.quit()

The problem is that the window doesn't even show up in the jupyter notebook . I litteraly copy pasted the code from the internet to make sure there wasn't any error, so I'm suspecting the problem comes from Jupyter itself (the video driver for example). Is there a workaround for this, or is this simply impossible to use pygame with Jupyter?

It seems just as Jupyter Notebook doesn't support GUIs, so I think they won't support pygame either…

Take a look at How can I build a GUI to use inside a jupyter notebook?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM