如何在PyGObject的TextView对象上添加占位符 [英] How to Add Placeholder on TextView Object in PyGObject
问题描述
我在条目
对象上添加了占位符:
self ._widget = Gtk.Entry()
self._widget.set_placeholder_text(Enter your name)
现在我想在 TextView
对象上添加占位符,但是我没有找到任何方法:
self._widget = Gtk.TextView()
您应该连接到 focus-in-event
和 focus-out-event
。如果 focus-out-event
上的文本缓冲区为空,请将占位符标志设置为true,添加占位符文本并添加一个可以选择用于样式的CSS类占位符文本灰色。如果 focus-in-event
中的占位符标记为真,请清空文本缓冲区并移除CSS类。
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()
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.
这篇关于如何在PyGObject的TextView对象上添加占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!