python的简单图形
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15886455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
simple graphics for python
提问by EasilyBaffled
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:
我正在用需要可视化的 python 进行模拟。我正在寻找 python 拥有的最简单的图形库。有什么可以让我做一些事情:
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.
有这么简单的事吗?3d 不是必须的,但它会很好。我在 python 3.3 中工作,据我所知,pygames 还没有在 Mac 上更新。我一直在使用 tkinter,但想要更简单的东西。
回答by Rushy Panchal
For simple graphics, you can use graphics.py.
对于简单的图形,您可以使用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.
它不包含在 Python 中,因此您应该将其保存为graphics.pyPython 可以看到的 Python 文件(最好命名为)---在您的sys.path.
Note:it is also available using pip install graphics.pysee link
注意:它也可以使用pip install graphics.py查看链接
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.
它非常容易学习并且已经内置了各种形状。没有原生 3D 图形(其中没有),但这样做很容易:对于立方体,绘制一个正方形,然后将另一个绘制到一边,然后将正方形的一个角连接到另一个正方形中的相应角。
Example using graphics.pyto create a square:
graphics.py用于创建正方形的示例:
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
回答by abarnert
pygamedoeswork 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 Homebrewit'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.
pygame确实适用于 3.x和 Mac OS X。任何最新的 Mac 版本都没有二进制安装程序,但这并没有太大的损失,因为二进制安装程序从来都不是很好。您基本上必须遵循 Unix 安装说明,并自己弄清楚如何安装所有先决条件(如果您使用Homebrew,它只是brew install sdl sdl_ttf … jpeg libpng),然后弄清楚如何告诉安装程序如何找到所有这些先决条件。您可能想查看(或什至可能使用)这个配方,以适应您自己的特定 Python 安装。
As far as I know, the other major alternatives for 3D graphics are PyOpenGLand 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 pygamebut built directly on native OpenGL and native windows on each platform, instead of on SDL.
据我所知,3D 图形的其他主要替代品是PyOpenGL和pyglet。前者是围绕 OpenGL 的一个非常直接的包装器,如果您用 GL 术语思考,这非常棒。后者是一个更高级别的库,有点类似pygame但直接构建在每个平台上的原生 OpenGL 和原生窗口上,而不是在 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 PyOpenGLsite and docs.
您可能还想查看Python 3D 软件集,它由PyOpenGL. 我不知道它有多最新,但他仍然从PyOpenGL网站和文档链接到它。
If you're looking for something mathematically-oriented, you may want to look at matplotlib, mplot3dand 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.
如果你正在寻找的东西数学为本,你可能想看看matplotlib,mplot3d和朋友。如果您最终尝试绘制复杂的几何形状和变换/相交/等。他们,这是你的朋友。如果您正在尝试构建一个简单的游戏或准 CAD 程序,则不是。
回答by Hugh Fisher
Visual Python, from www.vpython.org
Visual Python,来自www.vpython.org
Designed for people who aren't OpenGL hackers. It has a retained scene graph model rather than immediate, some built in controls, and there are quite a lot of scientific / engineering simulation examples floating around the Internet.
专为不是 OpenGL 黑客的人而设计。它有一个保留的场景图模型而不是直接的,一些内置的控件,并且有相当多的科学/工程模拟示例在互联网上流动。

