Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson3-1-1_DIY1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7740304e
authored
Apr 30, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
c66a449e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
diy1.py
diy2.py
diy1.py
View file @
7740304e
# 利用write()帮助悟空给诺依回信吧~
# 利用write()帮助悟空给诺依回信吧~
import
turtle
import
turtle
# 导入turtle模块
screen
=
turtle
.
Screen
()
screen
=
turtle
.
Screen
()
screen
.
bgcolor
(
"light blue"
)
screen
.
bgcolor
(
"light blue"
)
len
=
screen
.
textinput
(
"100"
,
"100"
)
len
=
screen
.
textinput
(
"100"
,
"100"
)
len
=
int
(
len
)
len
=
int
(
len
)
pen
=
turtle
.
Pen
()
pen
=
turtle
.
Pen
()
# 创建画笔
pen
.
write
(
"你好
\n
SB."
,
font
=
(
"Times"
,
30
,
"normal"
))
# 用write()方法将内容写在画布上,参1书写内容(\n换行)参2字体名称大小类型赋值给font(元组)
pen
.
hideturtle
()
pen
.
write
(
"诺依,
\n
turtle真好用,
\n
我会在画布上写字啦"
,
font
=
(
"Times"
,
30
,
"normal"
))
pen
.
hideturtle
()
# 调用hide turtle()方法隐藏画笔
len
=
60
len
=
60
pen
.
penup
()
pen
.
penup
()
pen
.
goto
(
100
,
100
)
pen
.
goto
(
100
,
100
)
...
@@ -19,4 +20,4 @@ pen.circle(len,180)
...
@@ -19,4 +20,4 @@ pen.circle(len,180)
pen
.
right
(
90
)
pen
.
right
(
90
)
pen
.
circle
(
len
,
180
)
pen
.
circle
(
len
,
180
)
pen
.
forward
(
2
*
len
)
pen
.
forward
(
2
*
len
)
turtle
.
done
()
turtle
.
done
()
# 保存画布
diy2.py
0 → 100644
View file @
7740304e
import
turtle
# 导入turtle模块
# 背景颜色
screen
=
turtle
.
Screen
()
# 取出画布背景并赋值给变量screen
screen
.
bgcolor
(
"light blue"
)
# 改变背景颜色为blue
# 写字
pen
=
turtle
.
Pen
()
# 创建画笔
pen
.
penup
()
# 抬起画笔
pen
.
goto
(
100
,
-
100
)
# 将文字画笔移至爱心右下角位置
# 用write()方法将内容写在画布上,参1书写内容(\n换行)参2字体名称大小类型赋值给font(元组)
pen
.
write
(
"诺依,
\n
turtle真好用,
\n
我会在画布上写字啦"
,
font
=
(
"Times"
,
15
,
"normal"
))
pen
.
hideturtle
()
# 调用hide turtle()方法隐藏画笔
# 画爱心
pen1
=
turtle
.
Pen
()
# 新建画笔pen1
pen1
.
pencolor
(
"red"
)
# 设置线条颜色
pen1
.
pensize
(
5
)
# 设置线条粗细
# 调用textinput()创建对话窗口参1标题,参2提示,并赋值给变量len
len
=
screen
.
textinput
(
"提示"
,
"你想要多大的爱心呀?"
)
lovesize
=
int
(
len
)
# 用int()转化变量len,并赋值给变量lovesize
# ⬆整数
pen1
.
left
(
45
)
# 左转45度
pen1
.
forward
(
2
*
lovesize
)
# 向前2*len
pen1
.
circle
(
lovesize
,
180
)
# 画出半圆len,180
pen1
.
right
(
90
)
# 右转90度
pen1
.
circle
(
lovesize
,
180
)
# 画出半圆len,180
pen1
.
forward
(
2
*
lovesize
)
# 向前2*len
pen1
.
hideturtle
()
# 隐藏画笔
turtle
.
done
()
# 保存画布
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment