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!