栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python语言系统学习:作品——“幸福一家人”Qt5与海龟结合

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python语言系统学习:作品——“幸福一家人”Qt5与海龟结合

一、“幸福一家人”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

  1. 方法

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)提高程序的扩展性

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/664468.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号