-1
我想制作一个移动应用程序,您可以在其中使用pygame进入计算器。我试图做的是当你点击计算器图像时,它会打开计算器应用程序,然后当你按下主页按钮时,它会回到主页。Pygame导入错误:没有模块名为py
问题:不过,如果你是在家里页面打开计算器应用程序后,然后再次尝试进入计算器应用它给了我一个错误:
ImportError: No module named 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
保存为calcu
保存为HOME2
保存为MAIN1
但是,如果我再次单击计算器应用程序图像,它不会带我回到主页,它只是打印鼠标点击的坐标。 –
@Krut它是不是再犯错误了?如果是这样,那么这个问题就回答了。 – StardustGogeta
但是我想回到主页后,我点击图像。我问的是这样的: “我想要做的是当你点击计算器图像,它打开计算器应用程序,然后当你按下主页按钮,它回到家里。“ –