How to Add Placeholder on TextView Object in PyGObject

好久不见. 提交于 2019-12-13 15:26:28

问题


I've added placeholder on Entry object:

self._widget = Gtk.Entry()
self._widget.set_placeholder_text("Enter your name")

Now I want to add placeholder on TextView object, but I didn't find any method for it:

self._widget = Gtk.TextView()

回答1:


You should connect to focus-in-event and focus-out-event. If the text buffer is empty on focus-out-event, set a placeholder flag to true, add the placeholder text, and add a CSS class that you can optionally use to style the placeholder text gray. If the placeholder flag is true on focus-in-event, empty the text buffer, and remove the CSS class.



来源:https://stackoverflow.com/questions/44715457/how-to-add-placeholder-on-textview-object-in-pygobject

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