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)
上面的代码是一个从菜单中调用的函数,它运行一个密码。密码运行后,我想要用户做的下一件事就是把它们带回那个菜单。
我试过,但我认为这可能是因为if语句中的第二轮for event in events
我们非常感谢您能想到的任何其他改进
提前致谢!