一、“幸福一家人”python和Qt5和海龟
1、PyQt设计界面:
2、对象命名:
3、源程序:
二、代码解释
A
def hart_arc():
for i in range(200):
turtle.right(1)#箭头向右转1
turtle.forward(2)#朝箭头方向走两个
def move_pen_position(x, y):
turtle.hideturtle() # 隐藏画笔(先)
turtle.up() # 提笔
turtle.goto(x, y) # 移动画笔到指定起始坐标(窗口中心为0,0)
turtle.down() # 下笔
turtle.showturtle() # 显示画笔
# 初始化
turtle.setup(width=800, height=500) # 窗口(画布)大小
turtle.color('red', 'pink') # 画笔颜色
turtle.pensize(3) # 画笔粗细
turtle.speed(1) # 描绘速度
# 初始化画笔起始坐标
move_pen_position(x=0,y=-180) # 移动画笔位置
turtle.left(140) # 向左旋转140度
turtle.begin_fill() # 标记背景填充位置
# 画心形直线( 左下方 )
turtle.forward(224) # 向前移动画笔,长度为224
# 画爱心圆弧
hart_arc() # 左侧圆弧
turtle.left(120) # 调整画笔角度
turtle.left(120) # 调整画笔角度
hart_arc() # 右侧圆弧
turtle.forward(224)# 画心形直线( 右下方 )
turtle.end_fill() # 标记背景填充结束位置
turtle.color('#CD5C5C', 'black') # 字体颜色
turtle.up()
# 在心中写字
turtle.goto(0, 0)#设置字体位置
turtle.write(('幸福一家人'), align="center",font=('',45))# font:设定字体、尺寸 align:中心对齐
# 点击窗口关闭程序
window = turtle.Screen()
window.exitonclick()
B
1,种类
class CPeople():
class CStudent (CPeople):
2,属性
ame=""
age=0
name4=""
age4=0
- 方法
def Output(self):
strOut=""
strOut=strOut+self.OutputName()+","
strOut=strOut+self.OutputAge()+","
def OutputResume(self):
strOutput=self.Output()+"n"
strOutput=strOutput+self.OutputName4()+","
strOutput=strOutput+self.OutputAge4()+","
4,输出
def Generate(self):
student=CStudent()
student.name=self.txtName.text()
student.age=self.numAge.value()
student.name4=self.txtName4.text()
student.age4=self.numAge4.value()
5,
def OutputName4(self):
strOutput="狗狗叫"+str(self.name4)
return strOutput
1:class CPeople---类的基本属性
2:Python Class的基础用法类(Class):用来描述具有相同的属性和方法的对象的 集合。它定义了该集合中每个对象所共有的属性和方法。对象是类的实例。
3:def关键字可以为类定义一个方法,与一般的函数定义不同,类方法必须包含参数self,且为第一个参数。
4:def函数名 :说这个函数是受保护的函数,只有类本身和其子类才能调用。
5:class CStudent (CPeople)---运用单继承方式
def OutputName4(self):---调用父类文本输出格式
strOutput="狗狗叫"+str(self.name4)
return strOutput
def OutputResume(self):----覆盖父类的方法
6:继承的作用是:
1)提高代码的重用性
2)提高程序的扩展性



