我想知道如何获取/限制输入到输入框中的字符数量,然后运行一个代码块,如果它等于某个值。我试过这个并没有得到任何东西。
import tkinter
window = tkinter.Tk()
encryption_code_entry = tkinter.Entry(window)
code_count = encryption_code_entry.get().upper()
code_count.split()
len(code_count.split())
def change_code():
for i in code_count:
if code_count == 26:
incorrect_label.destroy()
encryption_code = encryption_code_entry.get()
new_encryption_confirm.config(text="")
new_encryption_label.config(text="You have successfully changed the encryption code")
new_encryption_label.config(text="Please press the back button to return to the main menu")
elif code_count != 26:
incorrect_label.pack()
encryption_code_entry.pack()
new_encryption_label = tkinter.Label(window, text="Please enter your own encryption code in block capitals", font=('Helvetica', 14))
new_encryption_label.pack()
new_encryption_label2 = tkinter.Label(window, text="Make sure it is all 26 letters and do not repeat a letter to prevent errors", font=('Helvetica', 14))
new_encryption_label2.pack()
new_encryption_confirm = tkinter.Button(window, text="Confirm", command=change_code)
new_encryption_confirm.pack()
incorrect_label = tkinter.Label(window, text="You didn't enter all 26 characters, please try again", font=('Helvetica', 14))
window.mainloop()