Swampy.1.1 with Python 3

I am reading a Think Python book from Allen Downey. For chapter 4, you need to use a set of modules called Swampy . I downloaded and installed it.

The problem is that the modules were written in Python 2, and I have Python 3 (on Windows 7 RC1). When I started the TurtleWorld module from Swampy, I got error messages in the print and exec statements that now work in Python 3. I fixed these errors by including GUI and World modules in the code, including brackets and exec. I also received an error message that the Tkinter module was not found. It turned out that in Python 3, the module name is written in lowercase t.

The third error is more complicated: ImportError: there is no module named tkFont.

Does anyone have any ideas please? Thanks.

+3
source share
4 answers

Many important third-party libraries have not yet been rewritten for Python 3; you will have to stick with Python 2.x. There is no such thing. As stated on the official Python download page

If you do not know which version to use, start with Python 2.6.4; More existing third-party software is compatible with Python 2 than Python 3 right now.

+3
source

It seems 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()
+6
source

MAC: Python . , , . :

  • Python 3 , .. Swampy. Python 2 ( 2.7.5).
  • Swampy-2.1.1.tar.gz : https://pypi.python.org/pypi/swampy/2.1.1. , "".
  • , Swampy 2.1.1. , , .
  • : : Macintosh HD/Library/Frameworks/Python.framework//2.7/lib/python2.7/site-packages. REPEAT: "" "site-packages".
  • , Python "import swampy.TurtleWorld". ( → > ), , .
+1

There is a conversion tool to convert Python 2 code to work with Python 3: http://svn.python.org/view/sandbox/trunk/2to3/

I’m not sure how this applies to third-party libraries, but it may be worth passing it to the marshy code.

0
source

Source: https://habr.com/ru/post/1721500/


All Articles