首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问Gtk.Box in Gtk.Dialog?

如何访问Gtk.Box in Gtk.Dialog?
EN

Stack Overflow用户
提问于 2022-07-15 16:50:37
回答 1查看 52关注 0票数 0

在执行以下代码时,我会得到一个错误(Gtk-WARNING **: 18:33:56.632: Attempting to add a widget with type GtkBox to a GtkDialog, but as a GtkBin subclass a GtkDialog can only contain one widget at a time; it already contains a widget of type GtkBox):

代码语言:javascript
复制
def switchfile(self, widget):
    self.cd = None
    self.cd = {
        'win'   : Gtk.Dialog(),
        'entry' : Gtk.Entry(),
        'btnok' : Gtk.Button.new_from_icon_name("document-open-symbolic", Gtk.IconSize.MENU),
        'label' : Gtk.Label(),
        'vbox'  : Gtk.Box(orientation=Gtk.Orientation.VERTICAL),
        'hbox'  : Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    }

    self.cd['entry'].set_placeholder_text('Notebook Name')
    self.cd['btnok'].connect('clicked', self.switch_yes)

    self.cd['hbox'].pack_start(self.cd['entry'], True, True, 0)
    self.cd['hbox'].pack_start(self.cd['btnok'], True, True, 0)

    self.cd['vbox'].pack_start(self.cd['label'], True, True, 0)
    self.cd['vbox'].pack_start(self.cd['hbox'], True, True, 0)

    self.cd['vbox'].show_all()
       
    self.cd['win'].add(self.cd['vbox'])
    self.cd['win'].show_all()
    self.cd['win'].run()

但是,如果Gtk.Dialog中已经有一个Gtk.Dialog,我如何访问它?在关于堆栈溢出的另一个问题中,有一个Dialog.get_vbox()函数,但它是C/C++函数,当我使用bpython3列出Gtk.Dialog中的函数时,它没有任何东西,没有get_vbox(),也没有像get_vbox: no get_box()' and no get_container()这样的函数。

如何访问Gtk.Box中的Gtk.Dialog

信息:我正在使用3.0gi.repository.Gtk版本。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-17 10:40:59

现在我知道该怎么做了。

代码语言:javascript
复制
def switchfile(self, widget):
    self.cd = None
    self.cd = {
        'win'   : Gtk.Dialog(),
        'entry' : Gtk.Entry(),
        'btnok' : Gtk.Button.new_from_icon_name("document-open-symbolic", Gtk.IconSize.MENU),
        'label' : Gtk.Label(),
        'vbox'  : None,
        'hbox'  : Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    }

    self.cd['win'].add_buttons(
        Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
        Gtk.STOCK_OK, Gtk.ResponseType.OK
    )

    self.cd['vbox'] = self.cd['win'].get_content_area()

    self.cd['entry'].set_placeholder_text('Notebook Name')
    self.cd['btnok'].connect('clicked', self.switch_yes)

    self.cd['hbox'].pack_start(self.cd['entry'], True, True, 0)
    self.cd['hbox'].pack_start(self.cd['btnok'], True, True, 0)

    self.cd['vbox'].pack_start(self.cd['label'], True, True, 0)
    self.cd['vbox'].pack_start(self.cd['hbox'], True, True, 0)

    self.cd['vbox'].show_all()

    self.cd['win'].show_all()
    self.cd['win'].run()

重要的是这条线:

代码语言:javascript
复制
self.cd['vbox'] = self.cd['win'].get_content_area()

我不知道这个函数,但这是如何访问Gtk.Box中的Gtk.Dialog对象。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72997322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档