How to Create GUI Applications Under Linux Desktop Using PyGObject – Part 1

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.95/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Hanny Helal

A Linux & Foss user since 2010, working on many projects in the field of Free Software.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

18 Responses

  1. Nathan SR says:

    Thank you Hanny and for publishing this wonderful, step by step, instructional article, covering all aspects of GUI design, including packaging. In fact, I found the “Desktop Recorder” Application in part 3, so useful, that I developed a couple of my own applications, on similar lines and even packaged it for Debian as well.

    The entire project ( including packaging for Debian ) that I did, is shared for the benefit of viewers here :

    It can resolve most of the issues reported here and also give tips on coding and packaging as well. If you need any more inputs, a simple Google Search will do.

    Also, tips on Glade File Design can be seen here : and tips on icon design here :

    • Nathan SR says:

      P.S. For those interested, my other project source is shared here :

      • Nathan SR says:

        P.S. While Porting the above sources from Python 2.7 to Python 3.5, I realized a few new things :

        1. Support for tabs as an indentation method, has been removed
        2. 4 spaces is the preferred method of indentation
        3. Modules like subprocess, stringio etc. has undergone changes.

        I have upgraded the sources mentioned above, to reflect these new changes. Please download them again to get the latest version.

        • Nathan SR says:

          After gaining confidence, in Coding & Packaging, using Hanny’s Examples & the Sources Shared above, Viewers may try developing a few simple Apps, like for eg.

          1. A Manpage Creator/Studio App ( Just Google “linux create man page”. You will find examples / structure of a man page. It is just a matter of Adding a Few Special Keywords, while generating/filing a manpage, with your GUI Text Entry’s / Text View’s )

          2. A Diary App ( Just a matter of Reading / Writing to Files, based on the Date Picked, on a Calendar Widget )

          3. GUI for OS Commands, that can simplify tasks ( Accept Input on Text Entry’s/Views, Process Them, Show Result on Text Entry’s/Views )

          4. Apps listed on your Software Manager, to make them even better

          If you have developed a Unique, Well Tested ( Across Python Versions i.e. Change First Line of Script ) ( Across Linux Flavours / Versions i.e. Using Virtual Machines ) & Useful App for the World, then you may contact Debian Developers/Mentors ( Sponsors ) on the Debian IRC Channels List (Country Specific also available), who can help you, Publish Your Apps to the World. Also Sponsors Listed on their ftp-master site can be contacted on their Email for further progress.

          Note: Utility Apps may require multiple GIT Setups, for Upstream / Downstream Releases.

          Good Luck With Your Apps Development / Publishing !

        • Nathan SR says:

          Some info: The #!/usr/bin/python line in the code file above, refers to python 2 series, which is marked for end-of-life in 2020. Hence, viewers can substitute python with python3 in the file, as well as the debian/control and debian/rules files, explained in the part 4 article of this series.

          I have upgraded my sources shared above, to reflect all these, and incremented the version numbers to 2.1-1. Future upgrades to them will not carry a notice here.

  2. Jignesh says:

    I am new in developing GUI Application. Which is the best way to develop GUI App in gtk?

    Using Glade and writing GUI interface design code

  3. Paul says:

    None of your examples work…copying and pasting the code you provided gives me nothing but errors:

    “IndentationError: expected an indented block”

    PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version(‘Gtk’, ‘3.0’) before import to ensure that the right version gets loaded.
    from gi.repository import Gtk

    • Angel says:

      I would like to see an answer to this issue as I am having the same problem.

    • Christopher Truebig says:

      typing the code and make sure the indentation is consistent in python.
      this is a good website for learning pygtk with python 3

    • 4kd says:

      Had the same issue. A bit of Google and I found this:

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

      Concerning indention:
      Seems like the formatting was just lost. In python tabulation is used instead of bracketing. Colon must be followed by tabulated code, meaning that it’s a part of the block. It’s easy to restore if you can read the code for the slightest.

  4. NickJ says:

    File “./”, line 5
    def __init__(self):
    IndentationError: expected an indented block

  5. Amadeus says:

    Very useful tutorial. Thank you!

  6. Anonymus says:

    You have a minor syntax error in the first script, try to add parentheses to the print command

  7. Jimmy says:

    There is an error in the script of the builder. The name of the function in the Handler() should be the same as the one in glade.

    Instead of buttonclicked, it should be button1_clicked ;)

    Thanks for this tuto! Really helpful

  8. Israel says:

    Thanks a lot !!
    it’s exactly what I need

  9. Virneto says:

    Very cool and usefull content.
    I’ve put it already in my task list.


Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *