Skip to main content
 首页 » 编程设计

python之如何将 hboxes 和 vboxes 代码添加到 python gtk 中的笔记本选项卡

2024年10月24日10虾米哥

我正在为 ubuntu 开发一个小型 RSS 新闻应用程序。我用

创建了一个笔记本
notebook=gtk.Notebook() 
win.add(notebook) 
label1=gtk.Label() 
label1.set_text("one") 
notebook.append_page(label1,label1) 

我有这个带有 hbox、vbox 和滚动条的代码。

box1=gtk.VBox() 
win.add(box1) 
box2=gtk.HBox() 
box1.pack_start(box2) 
addressbar=gtk.Entry() 
box2.pack_start(addressbar) 
gobutton=gtk.Button("GO") 
box2.pack_start(gobutton) 
gobutton.connect('clicked',gob)     
scroller=gtk.ScrolledWindow() 
box1.pack_start(scroller) 
web=webkit.WebView() 
scroller.add(web) 

如何将第二个代码添加到第一个代码中的笔记本选项卡中?

请您参考如下方法:

你只需要将box1放入当前笔记本页面,而不是将其放入win。

label1 = gtk.Label("one") 
box1 = gtk.VBox() 
notebook = gtk.Notebook() 
notebook.append_page(box1, label1) 
win.add(notebook) 
 
box2 = gtk.HBox() 
box1.pack_start(box2) 
#etc 

顺便说一句,我没有看到您在小部件上调用 .show 方法;我假设您在创建所有内容后调用 win.show_all。