[英]Pygame failing to draw on Mac
First of all, I'm on macOS Mojave 10.14.1 with pygame 1.9.4.首先,我使用 macOS Mojave 10.14.1 和 pygame 1.9.4。
Also, I am using the PyCharm IDE and am using python 3.7.1.另外,我正在使用 PyCharm IDE 并使用 python 3.7.1。
I decided that it would be interesting to try out pygame, but drawing even a simple rectangle or image does not work.我决定尝试 pygame 会很有趣,但即使绘制一个简单的矩形或图像也不起作用。
Here is the code I have tried using to draw a rectangle, draw an image that is in the same directory as the file, and fill the window with white.这是我尝试用来绘制矩形、绘制与文件位于同一目录中的图像并用白色填充窗口的代码。 None of which work.
没有一个工作。
import pygame
pygame.init()
win = pygame.display.set_mode((600, 600))
pygame.display.set_caption("Snake")
image = pygame.image.load("java_logo.png")
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
win.fill((0, 255, 0))
pygame.draw.rect(win, (255, 0, 0), (50, 50, 50, 50))
win.blit(image, (200, 200))
pygame.display.flip()
pygame.quit()
Edit:编辑:
Here was the image used: https://i.imgur.com/OoSHkXX.png这是使用的图像: https : //i.imgur.com/OoSHkXX.png
This is known-issue Pygame not compatible with MacOS Mojave #555这是与 MacOS Mojave 不兼容的已知问题Pygame #555
According to issue's comments it has been fixed in pygame 1.9.5 only根据问题的评论,它仅在 pygame 1.9.5 中得到修复
UPD: It should work for python 3.6.5 UPD:它应该适用于 python 3.6.5
I've got the same problem than you last night.我昨晚遇到了和你一样的问题。 None window is loading when executing a very simple pygame code, a ball bouncing in a window.
执行一个非常简单的 pygame 代码时,没有窗口正在加载,一个球在窗口中弹跳。 The solution as related by other members is to install a newer version of pygame, in my case install the latest beta version of v2.0 of pygame lib.
其他成员相关的解决方案是安装较新版本的 pygame,在我的情况下安装最新的 pygame lib v2.0 测试版。
Here shell code to install in OS X Mojave with python3 installed.这是安装在安装了 python3 的 OS X Mojave 中的 shell 代码。
pip3 install pygame=2.0.0.dev6
Pygame still not working on Python 3.7.3, pygame 1.9.5, on OS X Mojave 10.14.3 Pygame 仍然无法在 OS X Mojave 10.14.3 上运行 Python 3.7.3、pygame 1.9.5
So pygame 1.9.5 does not fix the issue.所以 pygame 1.9.5 没有解决这个问题。
In a simple test program (see below) window opens, window caption works, but nothing is drawn.在一个简单的测试程序(见下文)窗口打开时,窗口标题有效,但没有绘制任何内容。
import pygame
import sys
pygame.init()
screen = pygame.display.set_mode((612,792))
pygame.display.set_caption("This works!")
red = (255,0,0)
screen.fill(red)
# point (0,0) is at upper left
pygame.draw.lines(screen,black,False,[(100,100),(150,200),(200,100)], 1)
pygame.display.update() #nothing is drawn
while (True):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
Using python 3.8 and couldn't load images.使用 python 3.8 并且无法加载图像。 Working as expected after
pip3 install pygame==2.0.0.dev10
pip3 install pygame==2.0.0.dev10
后按预期工作
For me I had to install Python version 3.6.0 of the Python page after using pip3 install pygame version 1.9.6对我来说,在使用 pip3 install pygame version 1.9.6 后,我必须安装 Python 页面的 Python 3.6.0 版
that works for me这对我行得通
For me i had to install对我来说,我必须安装
python 3.6 and pygame 1.9.6
python 3.6 和 pygame 1.9.6
on macOS Mojave 10.14.6 plus I had to add pygame.display.update()
在 macOS Mojave 10.14.6加上我不得不添加
pygame.display.update()
I think you forgot pygame.display.update() to update the screen.我想你忘记了 pygame.display.update() 来更新屏幕。 Also, for pygame.draw.rect(win, (255,0,0), (50,50,50,50)), that means that you draw a rectangle with the top-left corner at (50,50) (first two parts) with a width and length of 50 pixels each.
此外,对于 pygame.draw.rect(win, (255,0,0), (50,50,50,50)),这意味着您绘制一个矩形,其左上角位于 (50,50) (前两部分),宽度和长度各为 50 像素。 (last two parts).
(最后两部分)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.