2016-06-07 3 views
-1

pygame으로 계산기로 이동할 수있는 모바일 앱을 만들려고합니다. 내가하려는 것은 계산기 이미지를 클릭하면 계산기 응용 프로그램이 열리고 홈 버튼을 누르면 집으로 돌아갑니다.Pygame 가져 오기 오류 : py라는 모듈이 없습니다

문제 :하지만, 당신은 계산기 응용 프로그램을 연 후 홈 페이지에 있고, 당신은 다시 나에게 오류 제공하는 계산기 응용 프로그램으로 이동하려고하면 :

ImportError: No module named py

그러나이 오류를 나는 이미 파이 게임 모듈을 가지고 있기 때문에 오지 말아야한다. '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

는 caclimg로 저장
calcu,532 10은 메인 1 여기

답변

3

로 저장 집 2
main1
로 저장 HOME2
calcu
으로 저장이 문제를 해결하기위한 시도이다.

import pygame, time, sys 

img = pygame.image.load('main1.png') 
img2= pygame.image.load('calcu.png') 
img15=pygame.image.load('HOME2.png') 
img16=pygame.image.load('calcimg.png') 
w = 600 
h = 450 
screen = pygame.display.set_mode([w, h]) 
x=y=0 

pygame.init() 
WHITE=(255,255,255) 
location = 'home' 
while 1: 
    for event in pygame.event.get(): 
     if event.type==pygame.QUIT: 
      pygame.quit() 
      sys.exit() 
     if event.type == pygame.MOUSEBUTTONDOWN: 
      X= pygame.mouse.get_pos() 
      print("Click: ",X) 
      print(X[0],X[1]) 
      if B.collidepoint(X[0],X[1]): 
       location = 'calc' 
       print(location) 
      elif N.collidepoint(X[0],X[1]): 
       location = 'home' 
       print(location) 
    if location == 'home': 
     screen.blit(img,(0,0)) 
     B=screen.blit(img2,(37,305)) 
     N=screen.blit(img15,(94,355)) 
    if location == 'calc': 
     screen.blit(img16,(0,0)) 
     N=screen.blit(img15,(94,359)) 
    pygame.display.update() 

이것은 pygame과 아무 관련이 없습니다.

단순히 import sample.py을 쓰지 마십시오. import sample 만 사용하십시오.

자세한 내용은 here을 참조하십시오.

+0

그러나 다시 계산기 응용 프로그램 이미지를 클릭하면 다시 마우스로 클릭 좌표를 인쇄하는 홈 페이지로 돌아 가지 않습니다. –

+0

@Krut 오류가 더 이상 발생하지 않습니까? 그렇다면이 질문에 대한 답변이 제공됩니다. – StardustGogeta

+0

하지만 이미지를 클릭하면 홈페이지로 돌아가고 싶습니다. 내가 묻는 것은 "계산기 이미지를 클릭하면 계산기 응용 프로그램이 열리고 홈 버튼을 누르면됩니다. , 그것은 집으로 돌아 간다. " –