Python - Create a box in GTK+ 3 Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report Prerequisite - Python - Creating window, button in GTK+ 3 In GTK+ rather than specifying the position and size of each widget in the window, you can arrange your widgets in rows, columns, and/or tables. The size of your window is determined automatically, based on the sizes of the widgets it contains. And the sizes of the widgets are, in turn, determined by the amount of text they contain. Perfecting the layout can be completed by specifying padding distance and centering values of widgets. GTK+ arranges widgets hierarchically, using containers. There are two types of containers single-child containers and multiple-child containers. The most commonly used are vertical or horizontal boxes (Gtk.Box) and grids (Gtk.Grid). Follow below steps: import GTK+ 3 module. Create main window. Create Box. Create Button. Note: In IDE's like Pycharm we can install a package named PyGObject in order to use GTK+ 3. Boxes are invisible containers into which we can pack our widgets. When packing widgets into a horizontal box, the objects are inserted horizontally Gtk.Box.pack_start() (left to right ) or Gtk.Box.pack_end() (right to left). In a vertical box, widgets are packed from top to bottom or vice versa. Example : Creating a box with button. Python3 1== 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 ="GfG") # Create a horizontally orientated box container # having spacing 6 pixels self.box = Gtk.Box(spacing = 6) self.add(self.box) # Add a button to box container. # Gtk.Box.pack_start() widgets are positioned from left to right self.button1 = Gtk.Button(label ="Click Here") self.button1.connect("clicked", self.on_button1_clicked) self.box.pack_start(self.button1, True, True, 0) def on_button1_clicked(self, widget): print("Welcome to Geeks for Geeks.") win = MyWindow() win.connect("destroy", Gtk.main_quit) win.show_all() Gtk.main() Output : On clicking this we get. Create Quiz Comment A amalchandranmv Follow 1 Improve A amalchandranmv Follow 1 Improve Article Tags : Python Programming Language Write From Home Python-gui Python-GTK +1 More Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like