This article was updated and rechecked on 2nd of February 2022
Added: 19th of November 2020
Updated On: 2nd of February 2022
Viewed: 1,414 times
Create a new window using GTK and Python in Ubuntu and Ubuntu based distributions
I have always wanted to learn how to create an application in Ubuntu or an Ubuntu based distribution. There is a lot of information out there and If I'm honest it can get quite confusing.
I also don't mind admitting that I am no expert in this field, but I wanted to put something down that I could revisit later to give me a starting point. Please note if your using Kubuntu / KDE things will be different.
In this tutorial, we create a basic window using Python3 and GTK.
First of all you need to make sure python 3 is installed, most Ubuntu and Ubuntu and Ubuntu based distributions already include this, but to check enter the following command in the terminal.
If you don't get any ouput from the terminal enter the following command in the terminal
sudo apt-get install python3
Once installed let's create our first window
Create a new file on your Desktop name new_window.py
Next enter the following command in the terminal to get your path to python3
Create a new file on your desktop, and save this as new_window.py, then copy and paste the code below.
from gi.repository import Gtk
window = Gtk.Window(title="Hello World")
Next we need to make the script executable, so enter the following command
chmod +x new_window.py
Then enter the following in the terminal
If everthing works correctly a new window should pop up.