How to structure the program.

First start a Python File and name it whatever you want. Eg – anyname.py

Open it with any text editor

  • Now let’s first import PyGTK

import gi

  • Now to make sure your program uses GTK 3, add the following line of code

gi.require_version(“GTK”, “3.0”)

So the first section of our code will be –

import gi
gi.require_version(“GTK”, “3.0”)

  • If you are familiar with GUI programming, we run the GUI component in side a loop. To do this PyGTK, add the following line of code –

Gtk.main()

So the whole code for now will be –

import gi
gi.require_version(“GTK”, “3.0”)
//FIRST BLOCK 👆

//Mind this gap

//LAST BLOCK 👇
Gtk.main()

Run this to get nothing executed.

Installation

The official tutorial provides quite a concise description of installation.


What I would say is if u are on any Linux Distros, rest assured u are good to go and I believe people reading this are Linux Distros users, however to check,

  • Open Terminal
  • Enter

$ python

To start the python interpreter

  • Enter

>> import gi

If u encounter any error, Bad Luck…If not skip the rest of the steps, you are good to go

  • Exit the Python interpreter by

>> exit()

  • Enter

$ pip install PyGObject

After this, recheck again and then if u still get errors, head to Google😅

You can also refer to the Installation Guide.

Introduction

The official tutorial on Python GTK provides quite a good knowledge of making a python application on GTK, but it is quite difficult for a beginner to navigate through the docs and build a project. There are also quite rare good tutorials on the web. 

If you are a beginner in GTK, this is for you. However, basic knowledge of object oriented programming and Python is required. 

So how are the components arranged in this tutorial, 

  • We will first start with how to structure the program. 
  • We will then learn how to use each Pygtk Object like buttons, labels, etc…
  • Then we will use glade to build the GUI and how to connect it with our programs
  • And I guess that’s all you need to now to make a good GTK application