Sandcurves

Personal Website

Python is my favorite programming language, by far. One of the things that makes Python so fun to work with is that you can do all sorts of things with Python. From server-side web programming all the way to serious data crunching, Python is used to do it all.

As a hobbyist, I find it fun to be a generalist. I don’t program any one thing, but rather I write many different kinds of programs, and get to play around with a lot of the capability that Python has to offer. Python is, for me, a cool toy.

As I code, there are some tools that I find myself using frequently, and I tend to get to know those ones really well. For example I end up making a lot of websites, and so, the Django project is one that I know rather well.

But, there are some corners of Python that I don’t get to all that often, but I still use them from time to time.

Tkinter

One of those rarely used tools is tkinter.

There are many libraries that are used by Python programmers to spin up desktop applications (gui apps). And if you need something really sophisticated, maybe you need some of the more advanced tools. But, tkinter is packaged right in with Python’s standard library, so you don’t need to install anything extra.

And, with a bit of discipline and care, you can make some really cool applications just with tkinter.

Goal

Right, before we start looking at code, lets decide where we’re aiming to go. Firstly, I’m writing this blog post for myself, with two personal aims:

  • A template for starting new tkinter projects

  • A starting point for some commonly used items found in gui apps.

That’s what I want. Assuming someone other than me reads this blog post, let me try to make some assumptions about what you might want.

What you want…depends. Here are the assumptions that I’m making, just based on the fact that you found this blog post in the first place. You’ve done some basic Python, and you’re keen to start making programs that are more than just command line apps.

If those assumptions are wrong, I hope you either find something in this post that you can use, or at the very least, figure out that there’s nothing here for you early enough not to waste your time.

If my assumptions are right, you might just be at a level where may have struggled with the whole concept of object oriented programming (lets call it ’oop’). That was me when I first started looking at gui programming, nearly 10 years ago.

For me, I really struggled to understand what oop was all about for a long time, but when I started to learn gui programming, it all started to make sense. I think learning the basics of Python oop and the basics of gui programming work well together. The one needs the other, and gui programming, in a very real way, deals with ’objects’. A button or label or window, they’re all ’objects’ - that’s easy to understand.

If this is where you’re at - you know some python, you understand functions, loops, variables, and stuff like that, but oop has been a bit hard to get your head around, I would like to make a request here.

Learning hard things is possible, but it is often a bit…hard…, or downright frustrating. If you do struggle, try to read through this blog post a couple times. At some point, a light will go on in your head, when all the connections come together, and you’ll have the basic oop concepts used in Python down in your head.

This turned out to be a massive blog post, so, if this is all new to you, don’t try to get it all in one go. Work at it, until you gradually understand everything. Don’t just get building a basic gui app that works and leave it at that. Make sure you’ve got some understanding of how classes make objects, and how to use that in Python programming. If you ’get’ oop, gui programming just becomes filling in parameters from there - that is - it becomes rather easy.

Stick it out until you get it.

So, that’s what I want to do in this blog post:

  1. Build a basic tkinter gui template, and learn basic Python gui programming.

  2. Learn what classes and objects are in python, and learn basic Python oop.

It’s a big goal, but we can manage it. Let's get to it!