Skip to content
Related Articles

Related Articles

Python – Notebook in GTK+ 3

View Discussion
Improve Article
Save Article
  • Last Updated : 03 Jun, 2020
View Discussion
Improve Article
Save Article

The Gtk.Notebook widget is a Gtk.Container whose children are pages that can be switched between using tab labels along one edge.

Configuration options for GtkNotebook.

  1. Gtk.Notebook.set_tab_pos() for choosing which edge the tabs should appear.
  2. Gtk.Notebook.set_scrollable() for making notebook bigger and for adding scrolling options.
  3. Gtk.Notebook.popup_enable(), Gtk.Notebook.popup_disable() for whether there will be a popup menu allowing the users to switch pages

Follow below steps:

  • import GTK+ 3 module.
  • Create Notebook.
  • Create Box.


import gi
# Since a system can have multiple versions
# of GTK + installed, we want to make 
# sure that we are importing GTK + 3.
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class MyWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title ="Geeks for Geeks")
        # Create Notebook
        self.notebook = Gtk.Notebook()
        # Create Boxes
        self.page1 = Gtk.Box()
        self.page1.add(Gtk.Label("Welcome to Geeks for Geeks"))
        self.notebook.append_page(self.page1, Gtk.Label("Click Here"))
        self.page2 = Gtk.Box()
        self.page2.add(Gtk.Label("A computer science portal for geeks"))
        self.notebook.append_page(self.page2, Gtk.Label("Click Here"))
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
# Display the window.
# Start the GTK + processing loop

Output :

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!