0 votes
in Python by
How to use simple graphics for python

I am making a simulation in python that needs visualization. I am looking for the most simple graphics library python has. Is there anything that can let me do something along the lines of:

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 that simple? 3d is not a must but it would be nice. I'm working in python 3.3 and pygames hasn't been updated for that on a mac as far as I can tell. I've been working with tkinter but would like something a little easier.

1 Answer

0 votes
by
For simple graphics, you can use graphics.py.

It's not included with Python, so you should save it as a Python file (preferably named graphics.py) where Python can see it --- on your sys.path.

Note: it is also available using pip install graphics.py see link

It's very easy to learn and has various shapes already built-in. There are no native 3D graphics (none are in there) but it's easy to do so: for a cube, draw one square and another one to the side, and connect one corner of a square to the corresponding corner in the other square.

Example 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
...