PyGest: A Python tkinter Tutorial, Introduction

In this tutorial series, we are going to build a simple file hashing application using the Python standard library's interface to the TK GUI toolkit: tkinter. One can find some resistance to using tkinter in the Python community. However, my interest in tkinter was recently rekindled after watching "Tinkering with Tkinter", a presentation by Russel Keith-Magee, in which the Django developer makes a strong case for revisiting this often overlooked and under-appreciated component of the Python standard library . . .

As Keith-Magee points out, these days tkinter has a number of arguments in its favor: 1) it is in the standard library, 2) it has been greatly improved in recent years, with additions to its basic functionality (more widgets!) as well as improvements in the look and feel of the GUIs it can generate, and 3) new resources such as the website TkDocs provide a ton of information to get Python tkinter GUI apps up and running in a relatively short period of time. Keith-Magee walks the walk as well, having built Cricket – a GUI tool for running Django and Python test suites – entirely with tkinter.

Our goal here is much more modest. We're going to build a single view file hashing utility in a manner appropriate for people with some experience programming in Python, but little or even no experience in Python GUI programming. Why would anyone want to build a file hashing utility? Simply put, hash functions can help determine the integrity of a file. For example, if a developer provides the hash value of a given file along with a download, you can check the hash value of the file you've downloaded against the one supplied by the developer to test whether the file was corrupted or modified in transit. (If you're new to the concept of hash functions or need a refresher, check out our past article on How and Why to Check a File's Hash Value.)

With that determination, we can already specify the basic functionality that we'd like our tutorial application to have. It should be able to: 1) generate hash digests of a specified file, 2) check the result against a known hash value, 3) alert the user as to whether or not there is a match, and 4) provide a choice of hash functions to use in the process.

Our application will thus need: 1) a number of labels to orient the user, 2) input fields for the file's path and the hash value to check against, 3) mutually exclusive radio buttons to choose the hash value, and 4) some buttons to run the program and clear the contents of the input fields. The project will thus provide us with the opportunity to play around with the basic elements of any GUI application. Here's a simple mockup:


We are going to use Python 3.4 throughout, but much of the code that follows should also work in Python 2.7, and I'll try to provide pointers as to when and why it might not. In case anyone is interested, I'm building this using the PyCharm Free Community Edition IDE on a Macbook laptop. Please note, there may be, or rather, it is virtually certain that there are far better ways to code the application presented in this tutorial. I built the GUI on the basis of my own idiosyncratic research into the tkinter library, and have organized the project to make it easier to present and digest in this tutorial series.

In the next article, we'll begin by laying out the bare bones structure of the application. Then we'll use a grid layout manager to construct our primary view as a set of grids within grids. This post will be updated with links to each successive article in the series as it is uploaded to the site. Enjoy! As always, any and all suggestions, comments and critiques are welcome in the comments. You can follow along with the tutorial using the links below:

PyGest: A Python tkinter Tutorial, Part 1 
PyGest: A Python tkinter Tutotial, Part 2
PyGest: A Python tkinter Tutorial, Part 3 
PyGest: A Python tkinter Tutorial, Part 4 
PyGest: A Python tkinter Tutorial, Part 5 
PyGest: A Python tkinter Tutorial, Conclusion

3 comments:

  1. Thank you for useful post. It's great to learn somwthing new, that can be helpful. It can help in studying, for example at university. By the way, if you're studying at university here some new writing tools.

    ReplyDelete
  2. Python is one of the most important programming language, which you easily get learned to gain college credits for work experience which will provide ease to qualify in professional life

    ReplyDelete
  3. Good admin.keep it up.your blog was informative.The Millionaire Guide On
    Software Testing Training in Bangalore To Help You Get Rich.Learn more details.... Java Training in Bangalore
    Thank you for sharing.

    ReplyDelete