def decrypt(self, event): InvalidKey = ("Invalid key, re-enter key") NotInt = ("Not an integer") EncryptedText = self.Text.get() Key = self.Key.get() while True: try: Key = int(Key) except ValueError: self.useful_msg.set(NotInt) return False else: if Key >= 1 and Key <= 25: break else: self.useful_msg.set(InvalidKey) return False DecryptedText = Caesar.Decrypt(EncryptedText, Key) self.Out.set(DecryptedText) self.useful_msg.set("Decryption complete")