0
def ScytaleCipher():
    Title = cipherFont.render("Scytale Cipher", 10, textColour)
    Plaintext = inputFont.render("Plaintext: ", 10, textColour)
    Shift = inputFont.render("Shift: ", 10, textColour)
    background = pg.Surface(screen.get_size())
    background.fill(screenGray)
    background.blit(Title, (115,10))
    background.blit(Plaintext, (10,500))
    background.blit(Shift, (10,555))

    PlaintextBox = InputBox(125,500)
    ShiftBox = InputBox(75,555)

    EncryptButton = Button('Encrypt',340,490,125,50,buttonGray2)
    DecryptButton = Button('Decrypt',340,545,125,50,buttonGray2)
    BackButton = Button('Back', 10,10,100,50,buttonGray2)
    buttonsGroup = pg.sprite.Group(BackButton,EncryptButton,DecryptButton)

    Encrypt = False
    Decrypt = False

    while True:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                pg.quit()
                sys.exit()
            elif BackButton.isPressed(event):
                Menu()
            elif EncryptButton.isPressed(event):
                Encrypt = True
            elif DecryptButton.isPressed(event):
                Decrypt = True

            PlaintextBox.handleEvent(event)
            ShiftBox.handleEvent(event)

        screen.blit(background,(0, 0))

        buttonsGroup.draw(screen)
        PlaintextBox.drawBox(screen)
        ShiftBox.drawBox(screen)

        if Encrypt == True:
            cipher = ScytaleEncryption(PlaintextBox.text,ShiftBox.text)
            label1 = inputFont.render(cipher,1,textColour)
            screen.blit(label1,(500,550))
            for event in pg.event.get():
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_LEFT or event.key == pg.K_RIGHT:
                        Menu()
                    elif event.type == pg.MOUSEBUTTONDOWN:
                        Menu()

        pg.display.flip()
        clock.tick(60)

The above code is a function that is called from a menu, that runs a cipher. After the cipher has been ran, I want the next thing the user does to take them back to that Menu.

I have tried, but I think it might be because of the second round of for event in events in the if statement

Any other improvements you can think of will be much appreciated

Thanks in advance!

Badger8808
  • 142
  • 1
  • 12
  • what is `ScytaleEncryption` ? – furas Nov 29 '17 at 17:43
  • BTW: you can use `print()` to see what you have in variables and which part of code is executed. It helps to find what problem is. – furas Nov 29 '17 at 17:43
  • if `ScytaleCipher()` is executed from `Menu()` then you should use `return` to go back to previous `Menu()`, not execute new `Menu()`. Now you have in memory `menu(first instance) -> ScytaleCipher(first instance) -> menu(second instance) -> ScytaleCipher(second instance) -> etc.` – furas Nov 29 '17 at 17:45
  • ScytaleEncryption is just a separate function that encrypts the message that the user inputs in the text boxes. Thanks for the other tips – Badger8808 Nov 29 '17 at 22:19

0 Answers0