-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
但是我想回到主頁後,我點擊圖像。我問的是這樣的: 「我想要做的是當你點擊計算器圖像,它打開計算器應用程序,然後當你按下主頁按鈕,它回到家裏。「 –