我可以通過命令行導入pygame的,並通過我的所有其他 prorams,但它帶來了我的十字程序中的錯誤:ImportError:沒有名爲pygame的模塊?
回溯(最近通話最後一個): 文件「C:\用戶\家庭\桌面\ PYS \十字線(2)的.py」,1號線,在 進口pygame的 導入錯誤:沒有模塊名爲‘pygame的’
我不知道到底是什麼它都在談論,但 我認爲這可能是Windows Vista是一個垃圾洞(Vista是嚴重的毛病) 但我不太確定。有誰知道問題是什麼? 如果你需要它,這裏是代碼:
import pygame
import math
import sys
WHITE = (255, 255, 255)
BLACK = ( 0, 0, 0)
RED = (255, 0, 0)
BGCOLOR = WHITE
WINDOWWIDTH = 640
WINDOWHEIGHT = 480
class Control(object):
def __init__(self):
self.bullet_holes = []
self.screen = pg.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT))
self.done = False
self.clock = pg.time.Clock()
def update(self):
vis = False
pygame.mouse.get_visible(vis)
self.mousex,self.mousey = pg.mouse.get_pos()
self.screen.fill(BGCOLOR)
pygame.draw.circle(self.screen, RED, (320,240),50,10)
pygame.draw.circle(self.screen, WHITE, (320,240),40,10)
pygame.draw.circle(self.screen, RED, (320,240),30,10)
pygame.draw.circle(self.screen, WHITE, (320,240),20,10)
pygame.draw.circle(self.screen, RED, (320,240),10,10)
pygame.draw.line(self.screen, BLACK, (self.mousex - 2000, self.mousey),
(self.mousex + 2000, self.mousey))
pygame.draw.line(self.screen, BLACK, (self.mousex, self.mousey - 2000),
(self.mousex, self.mousey + 2000))
for bullet_pos in self.bullet_holes:
pygame.draw.circle(self.screen,BLACK,bullet_pos,5)
def event_loop(self):
for event in pg.event.get():
if event.type == pg.QUIT or (event.type == pg.KEYUP and
event.key==pg.K_ESCAPE):
self.done = True
elif event.type == pg.MOUSEBUTTONDOWN and event.button == 1:
self.bullet_holes.append(event.pos)
pygame.image.save(self.screen,'Highscores.png')
def main_loop(self):
while not self.done:
self.update()
self.event_loop()
pygame.display.flip()
self.clock.tick(60)
if __name__ == '__main__':
game = Control()
game.main_loop()
pygame.quit()
sys.exit()
您不必雙倍空間的代碼。只需將它縮進四個額外的空格(** {} **按鈕將自動爲您執行此操作)。 –
謝謝!我不知道! –