1

I'd like to know how to get/limit the amount of characters typed into an entry box then run a block of code if it equals a certain value. I've tried this and got nothing.

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()
Cœur
  • 37,241
  • 25
  • 195
  • 267
Inkblot
  • 708
  • 2
  • 8
  • 19
  • Have you seen [this](http://stackoverflow.com/questions/11491161/limiting-entry-on-a-tk-widget) post? – anderswb Oct 20 '15 at 20:05
  • getting the characters and limiting the characters can be two different things. Is your ultimate goal to limit the number of characters? It's possible to prevent the string from ever exceeding a certain number of characters, or you can let the user type anything, and then do validation afterwards. Which do you want? – Bryan Oakley Oct 20 '15 at 20:42
  • Do you want to get the length of the entry or limit the amount of characters stored in it? – Jonah Fleming Oct 20 '15 at 20:57
  • Read about Entry validation here: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/entry-validation.html. The for loop makes little sense, as i is not used in the loop and the body of the loop will do the same thing over and over. – Terry Jan Reedy Oct 20 '15 at 23:47

0 Answers0