tkinter : tackling import for python 2 and 3

tkinter logo
gui package for python

tkinter is the integrated GUIĀ package in python. It has had an import naming change in python 3. This is the main hindrance in making tkinter codes run on python 3 or vice versa. fortunately the fix is a simple one

Some syntax

in python 2 we imported as :

and in python 3 we import as :

notice the T in py2

The fix

Here is a tip for cross platforming :

What it does

it imports the py3 version, if ok, it continues if no … it imports the python2 version, simple !


Lives in Mauritius, cruising python waters for now.