简体   繁体   中英

Python GTK (Glade) Notebook

I'm currently developing a small application in Python with the use of GTK+ (and Glade). 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+

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. Perhabs a more 'clear' question: What Notebook function will be required to call a specific V/HBox with every different tab? 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. I was hoping for an easy way to display this main window (the gtkHbox ) ONLY when having Tab1 selected.

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... ;)

Not an answer, but it looks like "another.anon.coward" already answered this in a comment...

If you double click on the tab, then that page is selected for adding content in 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. Register for "switch-page" signal to find out which page has been switched to.

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. But if you want to do it programatically get the notebook object from the ui using the get_object method of Gtk.builder class. 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. though there is no signal named switch-page. its named switch_page. You can look at the list of signals of notebook here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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