在执行以下代码时,我会得到一个错误(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):
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.0的gi.repository.Gtk版本。
发布于 2022-07-17 10:40:59
现在我知道该怎么做了。
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()重要的是这条线:
self.cd['vbox'] = self.cd['win'].get_content_area()我不知道这个函数,但这是如何访问Gtk.Box中的Gtk.Dialog对象。
https://stackoverflow.com/questions/72997322
复制相似问题