Python – Swampy.1.1 with Python 3

pythonpython-3.x

I am reading the book Think Python by Allen Downey. For chapter 4, one has to use a suite of modules called Swampy. I have downloaded and installed it.

The problem is that the modules were written in Python 2 and I have Python 3 (in Windows 7 RC1). When I ran the TurtleWorld module from Swampy, I got error messages about the print and exec statements, which are now functions in Python 3. I fixed those errors by including parentheses with print and exec in the code of the GUI and World modules. I also got an error that the Tkinter module could not be found. It turned out that in Python 3, the module name is spelled with a lower case t.

The third error is more difficult: ImportError: No module named tkFont.

Does anyone have any idea, please? Thank you.

Best Solution

It looks like tkinter is finally catching up with Python 3 - tkFont has become tkinter.font

http://docs.pythonsprints.com/python3_porting/py-porting.html

#!/usr/bin/env python3.2
# -*- coding: utf-8 -*-
#
#       font_ex.py
#       

import tkinter

top = tkinter.Tk()

butt01 = tkinter.Button(top, text="Hello World", font=('Helvetica', 24,))

custom_font_serif = ('Times', 24, 'bold')
butt02 = tkinter.Button(top, text="Hello World", font=custom_font_serif)

custom_font_sans = ('Helvetica', 36, 'italic')
butt03 = tkinter.Button(top, text="Hello World", font=custom_font_sans)

butt01.pack()
butt02.pack()
butt03.pack()

top.mainloop()