On 07/12/15 13:12, Yuehua HU wrote:
> Function description:
> User input strings in Entry(Tkinter) widget, there are tip words displayed in
> this Entry widget,
> when the Entry widget is selected, the tip words are faded,
> when user begin to entering words into this Entry, the tip words are
> disappeared.
>
> Does anybody know the method to implement it with Entry and Label widget? Or
> any other method in python?
I'm hoping this is not a homework...
Try something like this for Python 2:
##
import Tkinter as tk
top = tk.Tk()
e = tk.Entry(top)
e.pack()
def greyText(ev):
e.config(foreground='grey')
def startEntry(ev):
e.delete(0,tk.END)
e.config(foreground='black')
e.unbind('')
e.insert(tk.END,"Help text")
e.bind('', greyText)
e.bind('', startEntry)
top.mainloop()
##
You'll need some tweaks to cater for the user changing
their mind and just blanking the field. In that case you
probably need to reinstate the hint and the key binding.
I leave that as an exercise...
By coincidence I was doing something very similar
to this yesterday! :-)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor