1 / 59
文档名称:

python 讲义.ppt

格式:ppt   页数:59页
下载后只包含 1 个 PPT 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

python 讲义.ppt

上传人:wc69885 2015/6/5 文件大小:0 KB

下载得到文件列表

python 讲义.ppt

文档介绍

文档介绍:第五章
面向对象与图形编程
overview
Have you noticed the dot notation with the file variable? ()
This is different than other functions that act on a variable, like abs(x), not ().
In Python, files are objects, meaning that the data and operations bined. The operations, called methods, are invoked using this dot notation.
Strings and lists are also objects. More on this later!
outline
§ 面向对象的编程
§ 图形编程
§ 应用图形对象
§ 图形应用例子
§ 坐标的选择
§ 交互图形
§ 图形模块资料
outline
§ 面向对象的编程
§ 图形编程
§ 应用图形对象
§ 图形应用例子
§ 坐标的选择
§ 图形交互界面
§ 图形模块资料
数据与操作:面向对象观点
对象(Object):集数据与操作于一身。对象知道一些信息
对象能对那些信息进行处理
计算:向对象发出请求操作的消息。
主动的数据类型
面向对象(Object-Oriented):软件系统由各种对象组成,对象之间通过消息进行交互。
现代软件系统几乎都是OO设计和实现。
OO基本概念
类(class):描述同类对象的共性
包含的数据
任何类型的数据,甚至可以是对其他对象的引用.
能执行的操作(方法)
对象(object):类的实例(instance)
同类的不同对象可有不同的数据值(实例变量),但能执行的操作是一样的
创建对象:使用类的构造器(constructor).
<类名>(<参量1>,<参量2>,…)
消息:请求对象执行它的方法.
<对象>.<方法名>(<参量1>,<参量2>,…)
Suppose the graphics processing system.
There are many kinds of objects:
Window, Image, Line, Oval, Pixmap
Point, Polygon, Rectangle, Text
Each point is an object, for an example.
Simple Graphics Programming
Each point object would contain data like:
x
Y
and several operations like:
draw
getX
getY
move
undraw

Simple Graphics Programming
9
Simple Graphics Programming
This chapter uses the library supplied with the supplemental materials.
Two location choices
In Python’s Lib directory with other libraries
In the same folder as your graphics program
10
Simple Graphics Programming
Since this is a library, we need to import the mands >>> import graphics
A graphics window is a place on the screen where the graphics will appear. >>> win = ()
mand creates a new window titled “Graphics Window.”