【问题标题】:Pygame window won't show up in JupyterPygame 窗口不会出现在 Jupyter 中
【发布时间】:2020-12-14 16:56:16
【问题描述】:

我目前正在尝试在 CoCalc 项目的 Jupyter 笔记本中编写一个小型 pygame 游戏。作为第一次测试,我只是尝试用这段代码显示一个窗口:

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()

问题在于窗口甚至没有出现在 jupyter 笔记本中。我从互联网上复制粘贴代码以确保没有任何错误,所以我怀疑问题来自 Jupyter 本身(例如视频驱动程序)。 是否有解决方法,或者这根本不可能将 pygame 与 Jupyter 一起使用?

【问题讨论】:

  • 您是否收到任何错误或警告?

标签: python pygame jupyter


【解决方案1】:

好像 Jupyter Notebook 不支持 GUI,所以我认为他们也不支持 pygame...

看看How can I build a GUI to use inside a jupyter notebook?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 2014-07-05
    • 1970-01-01
    • 2013-10-16
    相关资源
    最近更新 更多