0

I tried to create a basic GTK Container widget with the following code:

from Gtk3Modules import *
from gi.repository.GObject import GObject

class Ex(Gtk.Container):
    pass


btn = Gtk.Button("nss")

ab = Ex()
ab.add(btn)


w = Gtk.Window()
w.add(ab)
w.show_all()

when I launch this script, I get the following fatal error:

(example.py:2642): Gtk-WARNING **: GtkContainerClass::add not implemented for '__main__+Ex'
**
Gtk:ERROR:gtkwidget.c:12365:gtk_widget_real_realize: assertion failed: (!_gtk_widget_get_has_window (widget))
rlwrap: warning: python3 crashed, killed by SIGABRT (core dumped).
rlwrap itself has not crashed, but for transparency,
it will now kill itself with the same signal


warnings can be silenced by the --no-warnings (-n) option
Aborted (core dumped)
hoijui
  • 3,615
  • 2
  • 33
  • 41
Nomad
  • 918
  • 6
  • 23

1 Answers1

1

Gtk.Container is not a Widget it is an Interface that you have to implement. It is unlikely that is what you want to actually do as implementing a new container is not trivial.

What you want to use is probably Gtk.Box if you want it to contain multiple children or Gtk.Bin if you only want a single child.

TingPing
  • 2,129
  • 1
  • 12
  • 15
  • is `Gtk.Bin` most rudimentary object for adding single child ? why didn't you suggest `Gtk.EventBox` because it can be used for adding single child instead of `Gtk.Bin` thanks – Nomad Sep 10 '17 at 01:34
  • `Gtk.EventBox` is a subclass of `Gtk.Bin` with a few extra features. Upstream suggests `Gtk.Bin`: https://wiki.gnome.org/HowDoI/CustomWidgets – TingPing Sep 10 '17 at 02:10