How to Install PyGTK in Python on Linux?
Last Updated :
27 Jun, 2022
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.
Requirements:
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.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()
Execute the file and if a window pops up, then it means that your installation was successful.
Similar Reads
How to Install Pyglet in Python on Linux? The pyglet is a Python library. It is a cross-platform windowing and multimedia library and is planned for developing games and other visually-rich applications like GUI applications and many more. It has an active developer and user community so that users can easily solve issues. It also supports
2 min read
How to Install Packages in Python on Linux? To install a package in python, we use pip. The pip is a python package manager. In this tutorial, we will be discussing how we can install packages in python on a Linux system. To install packages in python on Linux, we must have python and pip installed on our Linux machine. As python comes preins
2 min read
How to Install pyperclip in Python on Linux? Pyperclip is a cross-platform Python module for copy and pasting, or we can say that it provides clipboard functionality. It was created to allow cross-platform copy-pasting in Python which was before missing. It is available for Python 2 and 3. In this article, we will look into the steps of instal
1 min read
How to Install PyGTK in Python on MacOS? PyGTK is a Python package or module that enables developers to work with GTK+ GUI Toolkit. This is how WikiBooks describes GTK+: "GTK+ is a highly usable, feature rich toolkit for creating graphical user interfaces which boasts cross platform compatibility and an easy to use API." And this is how gt
4 min read
How to Install Python on Linux This guide explains how to install Python on Linux machines. Python has become an essential programming language for developers, data scientists, and system administrators. It's used for various applications, including web development, data science, automation, and machine learning.This comprehensiv
15+ min read