0

I need to show warning message if the username is not entered.

Its like in the apps where when you click continue button without filling the field. It will show a message like ("username is required") like that.

16th Jul 2021, 5:58 PM
Santhos raj
Santhos raj - avatar
7 odpowiedzi
+ 9
Santhos raj , you can do it like this description: ▪︎use a variable and the input() function for storing the entered value ▪︎in next line check if variable is empty ▪︎in case of the variable is empty: use print to give an error message ▪︎if variable is not empty, continue with the next steps if you want to give the user the possibility to repeat input in case of variable is empty, put a loop around these steps mentioned above. in this case make sure that the loop can be left if input is ok happy coding and good success!
16th Jul 2021, 6:06 PM
Lothar
Lothar - avatar
+ 2
Santhos raj use get() method for getting the text from entry widget. from tkinter import* root=Tk() entry=Entry(text="hey") def check(): print(entry.get()) button=Button(text="Submit",command=check) entry.pack() button.pack() root.mainloop()
16th Jul 2021, 6:47 PM
Abhay
Abhay - avatar
+ 2
Use if statement I = input() If I: print("continue") else: print ("name is required")
16th Jul 2021, 7:19 PM
Sudo
Sudo - avatar
+ 1
Lothar can you help me how to find if a variable is empty? I used len function but it showed that entry type has no len()
16th Jul 2021, 6:09 PM
Santhos raj
Santhos raj - avatar
+ 1
Santhos raj Here's a possible solution: while True: if name := input("ENTER: "): break print("Please enter your name!") # Hope this helps
17th Jul 2021, 8:49 PM
Calvin Thomas
Calvin Thomas - avatar
0
Abhay so we need to get entry within the function?
17th Jul 2021, 3:44 AM
Santhos raj
Santhos raj - avatar
0
Sudo thanks I will try that
17th Jul 2021, 3:44 AM
Santhos raj
Santhos raj - avatar