did12345
did12345

Reputation: 57

Python getting back to the first function

I am doing a Photobooth with printing (and uploading) option. This project presents itself like this: Start screen with instructions --> preview results screen --> user chooses either to print or restart (or the timeout chooses restart for the user)

If the user chooses print then, printing is done, and a message is displayed (sleep method) before going back to the start screen.

Now, i have one main issue: Getting back to the start screen...

The simplified code is here:

def PreviewMontage(MontageFile):
    global LastTap
    LastTap = time.time()
    print("Session ID:", SessionID)
    print("Show something.")
    preview = pygame.image.load(MontageFile)
    PILpreview = Image.open(MontageFile)
    previewSize = PILpreview.size # returns (width, height) tuple
    #added /1.5
    ScaleW = AspectRatioCalc(previewSize[0]/1.5, previewSize[1]/1.5, SCREEN_HEIGHT)
    preview = pygame.transform.scale(preview, (ScaleW, SCREEN_HEIGHT))
    SetBlankScreen()
    background.blit(preview, (SCREEN_WIDTH/2-ScaleW/2, 0))
    PrintScreen()
    #inserting conditions here - get mouse
    camera.stop_preview()
    UpdateDisplay()
    Wait()
    return

def Wait():
    clock = pygame.time.Clock()
    waiting = True

    while waiting:
        time = 60
        time = time -1 
        for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFTMOUSEBUTTON:
            x, y = event.pos
            print("You pressed the left mouse button at (%d, %d)" % event.pos)
            LeftMouseButtonDown(x, y)
        if time == 0:
           waiting = False
return

I encounter the problem of getting back to the main screen, it seems that the Wait() function never ends...

Upvotes: 0

Views: 173

Answers (1)

Marcus Lind
Marcus Lind

Reputation: 11450

You are setting the time to 59 on every iteration of your while loop. It means time never reaches 0 and the loop is infinite.

Fix it by declaring time = 60 outside the while()

Upvotes: 1

Related Questions