Simple graphics for python

I am doing a simulation in python that needs to be rendered. I am looking for the simplest python graphics library. Is there anything that can allow me to do something according to:

setWindow(10,10) setCube(0,0,1,1,1)#windowX, windowY, width, length, hight, updateList = simUpdate for update in updateList: removeShape(0,0) setCube(0,0,1,1,1) 

Is there anything so simple? 3d is not necessary, but it would be nice. As far as I can tell, I am working in python 3.3 and pygames has not been updated for this on mac. I worked with tkinter, but it would be a little easier for me.

+7
source share
3 answers

For simple graphics, you can use graphics.py .

It is not part of Python, so you should save it as a Python file (preferably named graphics.py ), where Python can see it --- on your sys.path .

It is very easy to learn and has built-in forms. There is no native 3D graphics (not there), but it’s easy to do: for a cube, draw one square and the other to the side and connect one corner of the square with the corresponding angle in the other square.

An example of using graphics.py to create a square:

 from graphics import * win = GraphWin(width = 200, height = 200) # create a window win.setCoords(0, 0, 10, 10) # set the coordinates of the window; bottom left is (0, 0) and top right is (10, 10) mySquare = Rectangle(Point(1, 1), Point(9, 9)) # create a rectangle from (1, 1) to (9, 9) mySquare.draw(win) # draw it to the window win.getMouse() # pause before closing 
+8
source

pygame does work with 3.x and Mac OS X. There are no binary installers for any latest version of Mac, but this is not a big loss because binary installers have never been very good. You basically have to follow Unix installation instructions and figure out how to install all the prerequisites (if you use Homebrew , it's just brew install sdl sdl_ttf … jpeg libpng ), then figure out how to tell the setup how to find all these prerequisites. You can look at (or perhaps even use) this recipe adapted to your own Python installation.

As far as I know, other main alternatives for 3D graphics are PyOpenGL and pyglet . The first is a pretty straightforward wrapper around OpenGL, which is great if you think in terms of GL. The latter is a higher-level library, somewhat similar to pygame , but built directly on its own OpenGL and its own windows on each platform, and not on SDL.

You can also see the Python 3D Software Collection , which is maintained by the main author of PyOpenGL . I have no idea how relevant this is, but it still links to it from the PyOpenGL website and docs.

If you are looking for something mathematically oriented, you can see matplotlib , mplot3d and friends. If you are ultimately trying to display complex geometric shapes and transform / intersect / etc. them, this is your friend. If you are trying to create a simple game or quasi-CAD program, it is not.

+5
source

Visual Python, www.vpython.org

Designed for people who are not OpenGL hackers. It has a graph chart of a saved scene, rather than an immediate one, some built-in controls, and there are quite a few scientific / technical modeling examples floating around the Internet.

+3
source

All Articles