Question: I am creating a python tkiner app and setting my entry fields I have created an only letters function on my order class and I

I am creating a python tkiner app and setting my entry fields I have created an only letters function on my order class and I have it to set the length to greater than 0(not blank) for all entry fields (name, address, etc) however, I am trying to set the state to only accept 2 letters. I can get it to not accept lower than two but if i was to type out the state name it would still accept it. How do i modify the code to only allow 2 letters for the state entry but allow over 0 for the other entry fields?
Code snipted
def only_letters(input_text, length):
""" only letters function will validate input to ensure each only contains letters and is the
not blank"""
# reviewing all letter only input fields to ensure they do not include numbers and are not blank
return input_text.isalpha() and len(input_text)> length.
def receipt ():
cardholder_last_name = cardholder_l_name_entry.get()
# validating entry to be letters and not blank
if not only_letters(cardholder_last_name, 0):
messagebox.showerror("Error", "The card holder's last name can only contain letters and "
"cannot be blank! ")
return
# creating an address variable
c_address = address.get()
# validating entry to be letters and numbers and not blank
if c_address =="":
messagebox.showerror("Error", "Cardholder address must contain a valid street address "
"and cannot be blank!")
return
# creating city variable
city = city_entry.get()
# validating entry to be letters and not blank
if not only_letters(city,0):
messagebox.showerror("Error", "Your city can only contain letters and cannot be blank! ")
return
# creating state variable
state = state_entry.get()
# validating entry to be letters and to be at least 2 characters
if not only_letters(state,2):
messagebox.showerror("Error", "Your state must be the two letter abbreviation or spelled "
"out without spaces and it cannot be blank!")
return

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!