Unit Testing TkInter Apps (Shallow Thoughts)

Akkana's Musings on Open Source Computing and Technology, Science, and Nature.

Fri, 08 May 2026

Unit Testing TkInter Apps

I've been making a lot of tweaks lately to MetaPho, in particular its Python/TkInter based replacement for my C/GTK2 image viewer Pho.

Pho has always had quite a few modes: it can be fullscreen, in a window sized for the current image, or in a fixed-size window; images can be scaled to the window/screen size, or you can zoom in/out, or you can view them at full size (pixel for pixel). It's fairly common that when I fix a bug in one mode, it introduces a new bug in a different mode because of the way the scaling code works.

Ideally, in a complicated program, you guard against problems like that with automated tests. But that's hard to do in a GUI (graphical user interface) app. A window comes up, but how do you make it do different things? How do you check whether it's showing the right thing, or if it's the right size?

I've tried a couple times to find hints on how to unit test Python scripts in either Tk or GTK, but there's not much help available. I think most people just give up and don't test their GUIs — just as I've always given up.

This time, I decided to really dive in and see if I could write a TkInter unit test script for testing all those different TkPho modes. It wasn't easy, but now I have a basic framework that I should be able to use for other GUI apps as well.

Read more ...

Tags: , ,
[ 13:55 May 08, 2026    More programming | permalink to this entry | ]

Comments via Disqus:

blog comments powered by Disqus