Python Gtk.Entry placeholder text

a 夏天 提交于 2019-12-05 23:39:39

问题


i have a login-window with two gtk.Entry objects, one for username, one for password. How can i add some Ghosttext to the Entry, so there is written "Username" in the Entry but if you click inside the text dissapears.


回答1:


Starting with Gtk+ 3.2 it's possible to set placeholder text.

entry = Gtk.Entry()
entry.set_placeholder_text("I am a placeholder")



回答2:


I've found an example where .set_text() and .select_region() are used to preselect the text, so it is deleted when the user starts to type.

This doesn't seem to work if you have more than one Gtk.Entry fields, because only one can be selected at a time. I reckon you have to use a signal to delete the text when the Entry field is clicked.

If you can't figure it out, add some labels.



来源:https://stackoverflow.com/questions/11982799/python-gtk-entry-placeholder-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!