I have been using Gtk Entry till now which offers set_placeholder_text method to set a placeholder text in it however, looking in the documentation , I found no such method for TextView .
Is there any way I can set placeholder text in Gtk Textview ?
I think there was a question almost similar to this one. The idea is to, eg, use the
focus-in-event
andfocus-out-event
to check the text buffer content.Example:
The idea is that if no text or the existing text is the placeholder text it means there's no user input.
Python example
Glade ui file (save it as placeholder-textview.ui):
Python code:
Resulting UI:
Added a few widgets to keep the initial focus on other widgets.
Compare the behavior with the Gtk.Entry. It's very similar.