[英]Pygame could not be resolved
import pygame is underlined saying pygame could not be resolved.导入 pygame 下划线表示 pygame 无法解决。
Yet, when I launch my program, I have this message:然而,当我启动我的程序时,我收到了这样的信息:
c:\Users\Guillaume\PycharmProjects\Learn\Snake.py pygame 2.1.2 (SDL 2.0.18, Python 3.10.2) Hello from the pygame community. c:\Users\Guillaume\PycharmProjects\Learn\Snake.py pygame 2.1.2 (SDL 2.0.18, Python 3.10.2) Hello from the pygame community. https://www.pygame.org/contribute.html https://www.pygame.org/contribute.html
And when I run python -m pip install pygame --user
当我运行python -m pip install pygame --user
WARNING: Ignoring invalid distribution -ip (c:\python310\lib\site-packages) WARNING: Ignoring invalid distribution - (c:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -ip (c:\python310\lib\site-packages) WARNING: Ignoring invalid distribution - (c:\python310\lib\site-packages) Requirement already satisfied: pygame in c:\python310\lib\site-packages (2.1.2) WARNING: Ignoring invalid distribution -ip (c:\python310\lib\site-packages) WARNING: Ignoring invalid distribution - (c:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -ip (c:\python310\lib\site-packages) WARNING: Ignoring invalid distribution - (c:\python310\lib\site-packages)警告:忽略无效分发 -ip (c:\python310\lib\site-packages) 警告:忽略无效分发 - (c:\python310\lib\site-packages) 警告:忽略无效分发 -ip (c:\python310\ lib\site-packages) 警告:忽略无效分发 - (c:\python310\lib\site-packages) 已满足要求:c:\python310\lib\site-packages 中的 pygame:\python310\lib\site-packages (2.gnoring invalid Distribution:) -ip (c:\python310\lib\site-packages) 警告:忽略无效分发 - (c:\python310\lib\site-packages) 警告:忽略无效分发 -ip (c:\python310\lib\site-packages ) 警告:忽略无效分发 - (c:\python310\lib\site-packages)
So it seems like pygame is working.所以看起来 pygame 正在工作。
Though my window won't pop up, anyone?虽然我的 window 不会弹出,有人吗?
import pygame
def drawGrid(w, rows, surface):
sizeBtwn = w // rows
x = 0
y = 0
for l in range(rows):
x = x + sizeBtwn
y = y + sizeBtwn
pygame.draw.line(surface, (255,255,255), (x,0),(x,w))
pygame.draw.line(surface, (255,255,255), (0,y),(w,y))
def redrawWindow(surface):
global rows, width
surface.fill((0,0,0))
drawGrid(width,rows,surface)
pygame.display.update()
def main():
global rows, width
width=500
rows=20
win = pygame.display.set_mode((width,width))
flag=True
clock=pygame.time.Clock()
while flag:
pygame.time.delay(50) #time
clock.tick(10) #frame
redrawWindow(win)
I just solved a problem.我刚刚解决了一个问题。 You just have to write at the bottom (outside of the def main()) main() and keep the rest as it is.您只需在底部(def main() 之外)编写 main() 并保持 rest 原样。
import pygame
def drawGrid(w, rows, surface):
sizeBtwn = w // rows
x = 0
y = 0
for l in range(rows):
x = x + sizeBtwn
y = y + sizeBtwn
pygame.draw.line(surface, (255,255,255), (x,0),(x,w))
pygame.draw.line(surface, (255,255,255), (0,y),(w,y))
def redrawWindow(surface):
global rows, width
surface.fill((0,0,0))
drawGrid(width,rows,surface)
pygame.display.update()
def main():
global rows, width
width=500
rows=20
win = pygame.display.set_mode((width,width))
flag=True
clock=pygame.time.Clock()
while flag:
pygame.time.delay(50) #time
clock.tick(10) #frame
redrawWindow(win)
main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.