Python Gtk3 使用 Gtk.Container 创建简单的容器对象
Python Gtk3 creating simple container object with Gtk.Container
我尝试使用以下代码创建一个基本的 GTK 容器小部件:
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()
当我启动此脚本时,出现以下致命错误:
(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)
Gtk.Container
不是小部件,它是您必须实现的接口。这不太可能是您实际想要做的,因为实施新容器并非易事。
如果你想要它包含多个 children 或 Gtk.Bin
如果你只想要一个 child.[= 你想要使用的可能是 Gtk.Box
13=]
我尝试使用以下代码创建一个基本的 GTK 容器小部件:
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()
当我启动此脚本时,出现以下致命错误:
(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)
Gtk.Container
不是小部件,它是您必须实现的接口。这不太可能是您实际想要做的,因为实施新容器并非易事。
如果你想要它包含多个 children 或 Gtk.Bin
如果你只想要一个 child.[= 你想要使用的可能是 Gtk.Box
13=]