Python/Glade Tutorial:Part 1 (and an introduction)

Post your tutorials and howtos here.
User avatar
Posts: 1781
Joined: 18 Jul 2013 15:55
Location: Newport News, VA

Python/Glade Tutorial:Part 1 (and an introduction)

Postby ScottQuier » 08 May 2014 00:06

The very first thing I want to say is, "I'm not an expert when it comes to ANYTHING Linux. This includes Python and/or glade and/or Gtk widgets, etc. So, when you see something in this series of tutorials (Yes, I'm going to be subjecting you to a series of these things) that doesn't quite pass the "smell test", that's your signal to say something.

On the plus side, I've been a programmer of one sort or another since about 1977 (yep, I qualify for the gray-haired crowd) and I've used (and forgotten) more languages than I care to remember (hmmm forgotten .... not wanting to remember .... hmmm .... maybe I'm onto something there). :) Granted, some of these languages are not worth much and didn't get a lot of exposure.

Question: Anyone remember the "Forth" language (reference -- > ... anguage%29) Yep, I spent way too much time playing with that one.

Back on Topic: What I'm proposing to present in this series are little code snippets that demonstrate some feature or capability that I'm trying to figure out. The code being the results of "successfully" finding at least one way to get things done.

No tutorial intro would be complete without a long, long, long list of references. Sorry to disappoint. But here are some I've found useful so far: Set Up:
  • I guess the first thing that needs to be done is to make sure you have everything you're going to need. This link ( outlines what packages I first installed. Most (many?) are not going to be needed but, so far, everything I've tried has worked ... including compiling my own copy of the glade package (just for fun!).
  • In addition to that, I've also installed
Tutorial - Part 1 - This will demonstrate how to:
  • Display a window
  • Get data from an entry field
  • Write data to an entry field
  • Do a bit of error trapping (exception handling)
  • Shutdown the window and terminate the hosting Python process - yes, I found many way to fail at this!
It should be noted that the basis for this is found at these two links: The tutorial there is somewhat dated, is not compliant with Gtk+ 3, has more than a few errors, and the video (the youtube link) is very, very poor resolution. That being said, I don't propose to cover all that ground again. The links are there, take a good look, listen, and study.

To supplement those tutorials, I've included here the two files I created (following the tutorials as best I can). The value I've added is that this will work with Gtk+-3 and with glade 3.16.1 (from the repos, remember :) ). I've also removed the errors from the code and added comments to help explain what each set of lines is doing.

To use the example (code files at the bottom of the post):
  1. Download the tar file
  2. Move/copy the file to a good working location
  3. Open it with the archive software of your choice or use the command

    Code: Select all

    tar xfj Adder.tar.bz2
  4. Type the command

    Code: Select all

A "complete" tutorial has got to have pictures :)
If all goes as planned, the application should start up looking something like this:
Adder01.jpg (12.69 KiB) Viewed 1297 times
And, when you enter invalid info and click the "Add" button, you should get something like this:
Adder02.jpg (17.42 KiB) Viewed 1297 times
Coming in Python/Glade Tutorial:Part 2 - ComboBoxes, How to create them, populate them, use them. And, Part 2 will be the starting point for a future episode!

(2.16 KiB) Downloaded 94 times
Quoting zerozero, "The usage of PPA's in debian-based
systems is risky at best and entails serious compatibility
problems; usually it's the best way to destroy an install"

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 3 guests