【发布时间】:2016-06-07 20:01:28
【问题描述】:
我正在尝试制作一个移动应用程序,您可以在其中使用 pygame 进行计算器。我想要做的是,当您单击计算器图像时,它会打开计算器应用程序,然后当您按下主页按钮时,它会返回主页。
问题:但是,如果你在打开计算器应用程序后回到主页,然后你尝试再次进入计算器应用程序,它会给我一个错误:
ImportError: 没有名为 py 的模块
但是这个错误应该不会出现,因为我已经有了 pygame 模块。
代码保存为“mytake.py”
import pygame
#Loading Images
img = pygame.image.load('main1.png')
img2= pygame.image.load('calcu.png')
img15=pygame.image.load('HOME2.png')
#Setting Screen size
w = 600
h = 450
screen = pygame.display.set_mode([w, h])
x = y = 0
running = True
pygame.init()
WHITE=(255,255,255)
#Running loop
while running:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
screen.blit(img,(0,0))
B=screen.blit(img2,(37,305))
N=screen.blit(img15,(94,355))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
# Set the x, y postions of the mouse click
#mixer.music.play(0)
X= pygame.mouse.get_pos()
print "Click: ",X
print X[0],X[1]
#Open Calculator
if B.collidepoint(X[0],X[1]):
import calc.py
这是我保存为“calc.py”的计算器代码
import time
import pygame
#Loading images
img15=pygame.image.load('HOME2.png')
img16=pygame.image.load('calcimg.png')
#Screen Size
w = 600
h = 450
screen = pygame.display.set_mode([w, h])
x = y = 0
running = True
pygame.init()
WHITE=(255,255,255)
X= pygame.mouse.get_pos()
while running:
screen.blit(img16,(0,0))
N=screen.blit(img15,(94,359))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONUP:
# Set the x, y postions of the mouse click
X= pygame.mouse.get_pos()
print "Click: ",X
print X[0],X[1]
#Go back to home page
pygame.display.flip()
if N.collidepoint(X[0],X[1]):
import mytake.py
使用的图像使用的图像(根据给定名称保存):
另存为 caclimg
另存为计算
另存为 HOME2
另存为 main1
【问题讨论】:
标签: python python-2.7 pygame importerror