[FAQ] "Best" GUI toolkit for python

Terry Reedy tjreedy at udel.edu
Thu Oct 20 03:28:49 EDT 2016


On 10/20/2016 2:02 AM, Paul Rubin wrote:
> pozz <pozzugno at gmail.com> writes:
>> What can I do and what *can't* I do with Tkinter?

>I look at the very carefully tuned and sometimes animated UI's in fancy
> desktop applications like Gimp and don't see a way to do similar things
> in Tkinter.

Since I have not seen Gimp, I don't know what 'similar things' consist of.

However, one does animation (timed changes in some configuration 
attribute of a widget or widget item) with chained .after(milliseconds, 
function, *args) callbacks.

> Tkinter is ok for simple basic GUIs with text labels,
> buttons, an event loop that lets you catch mouse clicks, etc.  Gimp uses
> Gtk (I think) and does all kinds of fancy effects that seem difficult
> with tkinter, though now that I think about it, they might be doable
> with enough effort.

I have done simple animations (movement, color and size changes) for 
either my own learning or to answer StackOverflow questions.  Others 
have also posted demonstration code.  Search '[tkinter] animation', for 
example.

Tk and tkinter do not come with animation functions or classes per se. 
However, Python does have the turtle module, which animates canvas items.
 > python -m turtle # runs a demo and test
 > python -m turtledemo # front end for about 20 animation demos.
There may also be modules available in PyPI.

If I were doing many animations, I would write functions or classes such 
as (writing this for the first time)
animate_ramp(widget, option, milliseconds, steps, end_value)
animate_flip(widget, option, milliseconds, steps, alt_value)
If these were functions, they would be closures defining an inner 
function passed as the .after callback.

The first would linearly interpolate between start_value and end_value. 
The second would flip back and forth.  Possible enhancements: recognize 
option 'xy' to mean x,y position and interpolate both together.  Allow 
milliseconds to be a list of ints so that time steps do not have to be 
uniform.  For ramp, allow steps and end_values to both be lists (of 
equal length) so one call can interpolate multiple segments of a path. 
Allow alt_value to be a list that is cycled through.  Steps == None 
means run forever.

Terry Jan Reedy





More information about the Python-list mailing list