简体   繁体   English

Python GTK(Glade)笔记本

[英]Python GTK (Glade) Notebook

I'm currently developing a small application in Python with the use of GTK+ (and Glade).我目前正在使用 GTK+(和 Glade)在 Python 中开发一个小型应用程序。 Everything has been fairly simple to integrate so far, until I came up with the idea to add tabs instead of pop-ups.到目前为止,一切都很容易集成,直到我想出了添加选项卡而不是弹出窗口的想法。 Note: Still using Python 2.7+注意:仍然使用 Python 2.7+

Is there any easy way to implement already existing pages inside a new tab(notebook) like structure?有没有什么简单的方法可以在新标签(笔记本)之类的结构中实现现有页面? I'm having difficulties to find how to add content per separate tab created in glade.我很难找到如何为在 Glade 中创建的每个单独的选项卡添加内容。 Perhabs a more 'clear' question: What Notebook function will be required to call a specific V/HBox with every different tab?也许有一个更“明确”的问题:使用每个不同的选项卡调用特定的 V/HBox 需要什么 Notebook 函数? The current structure looks like (minus Menu / statusbar):当前结构看起来像(减去菜单/状态栏):

[ mainWindow ] --> (1) mainOverview (gtkVbox) --> (2A) mainContent (gtkHbox) ... other non-related content

The structure I was hoping for would look like:我希望的结构看起来像:

[ mainWindow ] --> (1) mainOverview --> (2) noteBook --> (3) Tab1 --> (4) mainContent (gtkHbox) -- (3) Tab2 --> (4) secondaryContent (gtkHbox)

The application itself works fine (multithreaded, fully functioning) without the tabs, the mainContent(gtkHbox) contains a file/recursive directory analyzer, a few checkboxes and a general overview.应用程序本身在没有选项卡的情况下运行良好(多线程,功能齐全), mainContent(gtkHbox)包含一个文件/递归目录分析器、几个复选框和一个总体概述。 I was hoping for an easy way to display this main window (the gtkHbox ) ONLY when having Tab1 selected.我希望的一种简单的方法来显示该主窗口( gtkHbox仅具有当) Tab1选择。

Having difficulties to find good reference pages that display a proper way to call content pages per notebook tab.很难找到好的参考页面,这些页面显示了按笔记本选项卡调用内容页面的正确方法。 Any reference-pages or useful links are very much appreciated!非常感谢任何参考页面或有用的链接! Thanks so far!到目前为止,谢谢! My apologies if this is a rather newbish question, I'm not new to Python coding, but interfaces on the other hand... ;)如果这是一个相当新的问题,我很抱歉,我对 Python 编码并不陌生,但另一方面,接口......;)

Not an answer, but it looks like "another.anon.coward" already answered this in a comment... 不是答案,但看起来像“another.anon.coward”已经在评论中回答了这个问题......

If you double click on the tab, then that page is selected for adding content in glade. 如果双击选项卡,则选择该页面以在glade中添加内容。 You can go ahead and add content for that page. 您可以继续为该页面添加内容。 As for switching you can use set_current_page to switch to page whose content you want to display. 至于切换,您可以使用set_current_page切换到要显示其内容的页面。 Register for "switch-page" signal to find out which page has been switched to. 注册“switch-page”信号以找出切换到的页面。

click on the notebook widget on the widget explorer(object inspector) on the left of glade.单击空地左侧的小部件浏览器(对象检查器)上的笔记本小部件。 Then use your left and right keyboard arrow keys to move from tab to tab.然后使用左右键盘箭头键在选项卡之间移动。 You can also double click on the label of the tab as pyrotherm has said in his answer.您也可以双击选项卡的标签,如pyrotherm 在他的回答中所说。 But if you want to do it programatically get the notebook object from the ui using the get_object method of Gtk.builder class.但是,如果您想以编程方式执行此操作,请使用 Gtk.builder 类的 get_object 方法从 ui 中获取 notebook 对象。 Then do this to add a page然后执行此操作以添加页面

builder = Gtk.Builder()
builder.add_from_file("example.glade")

self.notebook = builder.get_object("notebook1") # set the id of the notebook in glade
self.page1 = Gtk.Box()
self.page1.add(Gtk.Label(label="Default Page!"))
self.notebook.append_page(self.page1, Gtk.Label(label="Plain Title"))

Now add the content you want to it.现在添加你想要的内容。 Now on to signals.现在是信号。 Pyrotherm has already answered it. Pyrotherm 已经给出了答案。 though there is no signal named switch-page.虽然没有名为 switch-page 的信号。 its named switch_page.其名为 switch_page。 You can look at the list of signals of notebook here您可以在此处查看笔记本的信号列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM