Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 921
EasilyBaffled Avatar asked Apr 08 '13 18:04

EasilyBaffled


People also ask

Is Python good for graphics?

If you need to get a program out fast and don't mind coding the individual buttons, Python is a good language for graphical routines. However, if you need processing power and a high FPS, you are better off looking at other languages.

Does Python have built in graphics library?

Tkinter is one of Python's standard and easy-to-use Graphical User Interface (GUI) libraries that normally comes bundled with Python. There are many others with additional capabilities, platform support, and additional modern widgets.

Which module is used in Python for graphics?

The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support.


2 Answers

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
like image 143
Rushy Panchal Avatar answered Oct 07 '22 18:10

Rushy Panchal


pygame does work with 3.x, and with Mac OS X. There are no binary installers for any recent Mac version, but that's not much of a loss, because the binary installers were never very good. You will basically have to follow the Unix install directions, and figure out for yourself how to install all the prereqs (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 those prereqs. You may want to look at (or maybe even use) this recipe, adapted to your own particular Python installation.

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

You also might want to look at Python 3D Software Collection, which is maintained by the main author of PyOpenGL. I have no idea how up-to-date it is, but he's still linking to it from the PyOpenGL site and docs.

If you're looking for something mathematically-oriented, you may want to look at matplotlib, mplot3d and friends. If you're ultimately trying to graph complex geometric shapes and transform/intersect/etc. them, this is your friend. If you're trying to build a simple game or quasi-CAD program, it's not.

like image 35
abarnert Avatar answered Oct 07 '22 18:10

abarnert