+ 2
How to set placeholders for entrybox in tkinter ?
Since we can't use placeholder like html we are using default text in entry box.. I want to show the default text when user run the program if user hover over it then the default text should be disappeared.. if user typed something and then hover it back then the text should not be disappeared because user entered it. if user hover on it and entered nothing then the default text should be appear again.. I hope u got the point! Please help! My Attempt : https://code.sololearn.com/c4v36ndOnRRU/?ref=app
3 ответов
+ 2
As per your specification, the hover over event is called <Enter> and the mouse moving out is called <Leave>
So you need to bind some actions on this.
Also whenever the user enters something in the entry box, you should remove both bindings (unbind). I think you can do that by assigning a StringVar to the entrybox (textvariable parameter) and putting a write trace on the stringvar.
https://stackoverflow.com/questions/28196047/tkinter-is-stringvar-trace-called-when-the-stringvar-is-added-to-a-widget
So the whole recipe is here but I have no opportunity to test it now on mobile, I hope it helps and you can implement it with these instructions :)
+ 2
Tibor Santa
Now it's working As Expected 🎊🎉
but why it's not working without passing argument in function?
on line 10 and line 14
also we havn't use it in the function itself..
https://code.sololearn.com/c3q7XnG25Jjj/?ref=app
+ 1
Those are special types of function, also known as 'callback'. The parameter is mandatory and automatically passed to the function, it refers to the event which was triggered. So even if you don't actually use the event, it is mandatory parameter.
Read more here
https://www.pythontutorial.net/tkinter/tkinter-event-binding/