gtk.Toolbar 弃用警告修复
因此,我已经使用 gtk.Toolbar
对象一段时间了,并且使用了 append_item
方法,但收到了弃用警告。因此,我尝试了 insert_item
方法,但仍然收到弃用警告。因此,我尝试单独创建一个 gtk.ToolButto
n ,然后使用 insert
方法添加它,这消除了警告,但现在工具栏(之前工作得很好) )根本没有出现,也没有产生任何错误!因为我不再知道了,正确的方法是什么?
这是一些示例代码。我有 3 个工具栏,因此我只发布其中只有 1 个按钮的工具栏。
vBox = gtk.VBox(False, 0)
vBox.set_size_request(400,500)
vBox.set_border_width(2)
vBox.show()
prefWin.add(vBox)
bar = gtk.Toolbar()
bar.show()
vBoxFix = gtk.VBox(False,0)
vBoxFix.pack_end(bar,False,False,0)
vBoxFix.show()
vBox.pack_end(vBoxFix,False,False,0)
closeButt =gtk.ToolButton(None,'Close')
closeButt.connect('clicked',self.notYet)
closeButt.show()
bar.insert(closeButt,0)
So I've been using a gtk.Toolbar
object for a while and was using the append_item
method but was getting a deprecation warning. So I tried the insert_item
method and still got a deprecation warning. So I tried creating a gtk.ToolButto
n separately and then using the insert
method to add it which got rid of the warning but now the toolbar (which was working perfectly fine before) is not showing up at all and no errors are produced!!! What is the proper way to do this because I have no idea anymore?
Here is some example code. I have 3 toolbars so I'm only posting the 1 that has only 1 button on it.
vBox = gtk.VBox(False, 0)
vBox.set_size_request(400,500)
vBox.set_border_width(2)
vBox.show()
prefWin.add(vBox)
bar = gtk.Toolbar()
bar.show()
vBoxFix = gtk.VBox(False,0)
vBoxFix.pack_end(bar,False,False,0)
vBoxFix.show()
vBox.pack_end(vBoxFix,False,False,0)
closeButt =gtk.ToolButton(None,'Close')
closeButt.connect('clicked',self.notYet)
closeButt.show()
bar.insert(closeButt,0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
insert
方法似乎是正确的方法。您是否确保在某处show
工具栏,也许通过使用父级的show_all
方法?如果是这样,您是否将工具栏打包到窗口中的一个框中,以确保窗口本身实际上是工具栏的祖先?The
insert
method appears to be the correct one. Did you make sure toshow
the toolbar somewhere, perhaps by using theshow_all
method of the parent? And if so, did you pack the toolbar into a box in the window, to make sure that the window itself actually is an ancestor of the toolbar?