[Python] How do I check if the username's length is too long

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have this function that will take 3 parameters, and display it on a label once a button is pressed.

    It doesn't work :((

    Here is the code for the function:

    def display_username(firstname, middlename, lastname): # this function will take 3 parameters, the first name, last name, and middle name of the user

    while i==0 :
    full_name = f"{firstname} {middlename} {lastname}" # using a formatted string to piece the component of the full name together, defining it as full_name
    label.config( text=f"Hello, {full_name}!") # configure the label create earlier to display the full_name and with the word 'Hello' in front of it as a greeting message
    label.place(x=300,
    y=150) # configure the location of the label to appear acoordingly at those x and y coordinates on the app
    i == 1
    if len(firstname_entry.get(1.0,END)) > 6:
    tkinter.messagebox.showinfo("Notification",'First name is too long!, should be less than 6 characters')
    elif len(middlename_entry.get(1.0,END)) > 10:
    tkinter.messagebox.showinfo("Notification", 'Middle name is too long!, should be less than 10 characters')
    elif len(lastname_entry.get(1.0,END)) > 7:
    tkinter.messagebox.showinfo("Notification", 'Last name is too long!, should be less than 7 characters')


    Here is the code for the button:

    Submit_name = Button(tab1, text='Say Hello:D',command=lambda: display_username(firstname_entry.get(), middlename_entry.get(),lastname_entry.get()))
    # create a button for the using the display username function, displaying the user's information in first->last name order by getting the information typed in the texbox. The command = lambda is used to take the value of first name, middle name and last name to pass it t the display_user function
    Submit_name.place(x=400, y=200, width=150, height=30)
    # define the location for the button


    i want it to check for the length of first, middle and last name and send users a notification saying their name is too long and do nothing until the name is at a desirable. I also want it to take parameters and also use while loops in the function. IT doesnt work, the terminal said that it took 1 positional argument but 3 were given

    Continue reading...

Compartilhe esta Página