I am trying to create a custom Gtk text entry. The basic idea is to put a button inside of a text entry. Here is a shortened version of my full code:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
builder = Gtk.Builder()
button = Gtk.Button('button')
entry = Gtk.Entry()
entry.add_child(builder, button, "button")
The button does not get shown and it fails with the error:
(pygtk_foobar.py:26622): Gtk-CRITICAL **: gtk_buildable_add_child:
assertion 'iface->add_child != NULL' failed
Any suggestions?
A
GtkEntrywidget is not aGtkContainer, and thus it cannot have child widgets added or removed to it.Only widgets that inherit from the
GtkContainerclass can have children in GTK+.If you want to put a button next to a text entry, you should pack both widgets into a container like
GtkBox, e.g.:This will create a box with an entry and a button.