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.
8 Réponses
+ 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!
+ 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()
+ 2
Use if statement
I = input()
If I:
print("continue")
else:
print ("name is required")
+ 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()
+ 1
Santhos raj Here's a possible solution:
while True:
if name := input("ENTER: "): break
print("Please enter your name!")
# Hope this helps
0
Abhay so we need to get entry within the function?
0
Sudo thanks I will try that