Python最简单的图形编程
2015-06-07 23:53
711 查看
使用Python进行图像编程,要使用到Graphics库。Graphics库可以从http://mcsp.wartburg.edu/zelle/python/graphics.py获取。在Windows平台上将下载的graphics.py保存在C:\Python31\Lib\site-packages即可。
下面的代码显示了如何画点、画线、画圆、画矩形、画椭圆以及显示文字。
from graphics import *
#设置画布窗口名和尺寸
win = GraphWin('CSSA', 700, 700)
#画点
pt = Point(100, 100)
pt.draw(win)
#画圆
cir = Circle(Point(200, 200), 75)
cir.draw(win)
cir.setOutline('red') #外围轮廓颜色
cir.setFill('yellow') #填充颜色
#画线
line = Line(Point(650, 100), Point(250, 100))
line.draw(win)
#画矩形
rect = Rectangle(Point(300, 300), Point(400, 400))
rect.setFill('red') #填充颜色
rect.draw(win)
#画椭圆
oval = Oval(Point(450, 450), Point(600, 600))
oval.setFill('red') #填充颜色
oval.draw(win)
#显示文字
message = Text(Point(win.getWidth()/2, 20), 'Click anywhere to quit.')
message.draw(win)
#关闭画布窗口
win.getMouse()
win.close()
下面的代码显示了如何画点、画线、画圆、画矩形、画椭圆以及显示文字。
from graphics import *
#设置画布窗口名和尺寸
win = GraphWin('CSSA', 700, 700)
#画点
pt = Point(100, 100)
pt.draw(win)
#画圆
cir = Circle(Point(200, 200), 75)
cir.draw(win)
cir.setOutline('red') #外围轮廓颜色
cir.setFill('yellow') #填充颜色
#画线
line = Line(Point(650, 100), Point(250, 100))
line.draw(win)
#画矩形
rect = Rectangle(Point(300, 300), Point(400, 400))
rect.setFill('red') #填充颜色
rect.draw(win)
#画椭圆
oval = Oval(Point(450, 450), Point(600, 600))
oval.setFill('red') #填充颜色
oval.draw(win)
#显示文字
message = Text(Point(win.getWidth()/2, 20), 'Click anywhere to quit.')
message.draw(win)
#关闭画布窗口
win.getMouse()
win.close()
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- 肯特·贝克:改变人生的代码整理魔法
- 你应该学习哪种编程语言?