我有一些代码要求用户输入 26 个字符来制作自己的加密代码,如果它是 26 个字符长并且不是字母表或预设encryption_code
,代码将改变encryption_code
无论他们输入什么。
import tkinter
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
encryption_code = 'LFWOAYUISVKMNXPBDCRJTQEGHZ'
window = tkinter.Tk()
window.title("Encryption/Decryption")
change_frame = tkinter.Frame(window)
changed_frame = tkinter.Frame(window)
encrypt_entry = tkinter.Entry(change_frame)
def code_change():
global changed_frame
global encrypt_entry
print(len(encrypt_entry.get()))
if encrypt_entry.get() == 'LFWOAYUISVKMNXPBDCRJTQEGHZ' or 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
encrypt_entry.delete(0, tkinter.END)
changed_incorrect.configure(background=window.cget('bg'))
changed_incorrect.config(text="Please enter a different code", foreground='red')
changed_incorrect.pack()
changed_frame.pack()
if len(encrypt_entry.get()) == 26:
encryption_code = encrypt_entry.get()
encrypt_entry.delete(0, tkinter.END)
changed_label.configure(background=window.cget('bg'))
changed_label.config(text="You have successfully changed the encryption code!")
change_header.config(text=str(encryption_code))
changed_incorrect.pack_forget()
changed_label.pack()
changed_frame.pack()
elif len(encrypt_entry.get()) < 26 or len(encrypt_entry.get()) > 26:
changed_incorrect.configure(background=window.cget('bg'))
changed_incorrect.config(text="Please enter only 26 characters", foreground='red')
changed_label.pack_forget()
changed_incorrect.pack()
changed_frame.pack()
change_label = tkinter.Label(change_frame, text="Please enter your own encryption code in block capitals", font=('Helvetica', 12))
change_header = tkinter.Label(change_frame, text="Make sure it is all 26 letters and do not repeat a letter to prevent errors", font=('Helvetica', 12))
change_confirm = ttk.Button(change_frame, text="Confirm", width=20, command=code_change)
changed_label = tkinter.Label(changed_frame, text="You have successfully changed the encryption code!", font=('Helvetica', 14))
changed_incorrect = tkinter.Label(changed_frame, text="Please enter your code again", font=('Helvetica', 14))
change_label.pack()
change_header.pack()
encrypt_entry.pack()
change_confirm.pack()
change_frame.pack()
window.mainloop()
我的问题是每当我尝试输入 26 个字符时,例如QWERTYUIOPASDFGHJKLZXCVBNM,它告诉我我还没有输入 26 个字符,而它显然是 26 个字符,并且该消息仅在用户未输入 26 个字符时才会弹出。
更新:使用 print(len(encrypt_entry.get())) 显示我的条目是 26,但我的代码说它不是 26 个字符。