【问题标题】:Python Gtk3 creating simple container object with Gtk.ContainerPython Gtk3 使用 Gtk.Container 创建简单的容器对象
【发布时间】:2017-09-10 18:52:43
【问题描述】:

我尝试使用以下代码创建一个基本的 GTK Container 小部件:

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)

【问题讨论】:

    标签: gtk3 pygobject


    【解决方案1】:

    Gtk.Container 不是小部件,它是您必须实现的接口。这不太可能是您真正想要做的,因为实现新容器并非易事。

    如果您希望它包含多个孩子,您可能想要使用Gtk.Box,如果您只想要一个孩子,则可能是Gtk.Bin

    【讨论】:

    • Gtk.Bin 添加单个孩子的最基本对象吗?你为什么不建议Gtk.EventBox 因为它可以用于添加单个孩子而不是Gtk.Bin 谢谢
    • Gtk.EventBoxGtk.Bin 的子类,具有一些额外的功能。上游建议Gtk.Binwiki.gnome.org/HowDoI/CustomWidgets
    猜你喜欢
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    相关资源
    最近更新 更多