Skip to content
Related Articles
Open in App
Not now

Related Articles

How to Install PyGTK in Python on Linux?

Improve Article
Save Article
  • Last Updated : 27 Jun, 2022
Improve Article
Save Article

PyGTK module allows GUI development using Python. It is an open-source and cross-platform library that provides an interface to the GIMP toolkit (GTK) in python. It is accessed through the PyGObject package which provides bindings for GObject-based libraries like GTK. Note that in python3, PyGTK and GTK are the same things. It is a great alternative to the Tkinter module which comes bundled with python. It provides a lot of tools and elements for constructing a GUI. You can install it on Linux, Mac, or Windows. In this article, we will see how to install PyGTK on Linux.


Installation of PyGTK in Python on Linux

Follow the below steps, to install PyGTK in Python on Linux Operating System.

Step 1: Let’s start by installing Python. To do so, run the following command in your terminal

sudo apt install python3


Step 2: Now, run the following command to install the PIP package manager which we will use to install the PyGTK module. 

sudo apt install python3-pip


Step 3: Now, PyGTK is accessed through the PyGObject package. So, if we install the PyGObject package, we will have access to the entire GObject-based libraries, which include GTK. To Install PyGObject, GTK, let’s, and other required dependencies, run the following command.

sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0


That’s it, now let’s verify if we are able to access GTK in python.

Verifying PyGTK package installation on Linux

Create a new python file with the following contents

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

window = Gtk.Window(title="Test Window")
window.connect("destroy", Gtk.main_quit)

Execute the file and if a window pops up, then it means that your installation was successful.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!