Wie überprüfe ich, ob die Länge des Benutzernamens zu lang istPython

Python-Programme
Anonymous
 Wie überprüfe ich, ob die Länge des Benutzernamens zu lang ist

Post by Anonymous »

Ich habe diese Funktion, die 3 Parameter aufnimmt und sie auf einem Etikett anzeigt, sobald eine Taste gedrückt wird.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')
< /code>
Hier ist der Code für die Schaltfläche: < /p>
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
< /code>
Ich möchte, dass es nach der Länge von First-, Middle- und Nachname überprüft und den Benutzern eine Benachrichtigung sendet, die besagt, dass ihr Name zu lang ist und nichts unternimmt, bis der Name bei einem wünschenswerten ist. Ich möchte auch, dass es Parameter nimmt und auch während der Schleife in der Funktion verwendet wird.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post