1

I've created some simple functions to limit my entry, but I'm a little bit stuck: first of all def lowercase_letter_entry is not working and it do not edit my entry in lowercase. Second the functions that work they only do so once, after that they are kinda useless. I did try to solve this with for and while true but I've only managed to make repeat an infinity of time the warning message. Also I know is kinda of a dumb question but right now I'm using the function changing my_entry in what variable I need. Is there a way to make the def "neutral" and make them work with all my entry without having to edit the name? (hope I've menage to make a little of sense.

import tkinter  
from tkinter import messagebox

def lowercase_letter_entry(P):
   if P.isalpha() or P == "":
     if P.islower():
        return True
     else:
      if not P.islower():
       P.get()lower()
       return True
   else:
    messagebox.showwarning("Warning","Only letters are allowed")
    return False

Thank you and have a nice day!

1 Answers1

1

The validation function must always return True or False or it will disable itself. You have many cases where it will return None.

Is there a way to make the def "neutral" and make them work with all my entry without having to edit the name?

They are that way by default. You shouldn't be calling my_entry.get() inside the function. Your P parameter contains the string you should be validating against, there's no need to explicitly fetch it.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Thank you everything works except the entry that is not edited in lowercase and I can't figure why not. I edited my code in my first questions. Thanks – Carlo Marrone Apr 16 '20 at 06:29
  • @CarloMarrone: calling `P.lower()` accomplishes nothing. The validation function function is designed for validation, not for modifying the data as it is being typed. – Bryan Oakley Apr 16 '20 at 13:58