PythonTurtle是一个Turtle图形库,可以在Python中创建简单的图形并进行可视化编程
▥Python
𝄐 0
python turtle.screen,python turtle screensize,python中screen.fill,python screenshot,turtle.screen(),python中的screen
PythonTurtle是一个Turtle图形库,可以在Python中创建简单的图形并进行可视化编程。其中,PythonTurtleScreen/Screen对象提供了许多方法和函数来操作绘图界面。
1. screensize():设置绘图窗口的大小(像素)。例如:
python
from turtle import Screen
screen = Screen()
screen.screensize(500, 500)
2. bgcolor(color):设置绘图窗口的背景色。例如:
python
from turtle import Screen
screen = Screen()
screen.bgcolor("lightblue")
3. title(titlestring):设置绘图窗口的标题。例如:
python
from turtle import Screen
screen = Screen()
screen.title("My Turtle Drawing")
4. setup(width, height, startx, starty):设置绘图窗口的大小和位置。例如:
python
from turtle import Screen
screen = Screen()
screen.setup(500, 500, 0, 0)
5. exitonclick():点击关闭按钮后退出程序。例如:
python
from turtle import Screen
screen = Screen()
# do some drawing here
screen.exitonclick()
6. onclick(fun, btn=1, add=None):当鼠标在窗口内单击时调用指定的函数。例如:
python
from turtle import Screen, Turtle
def draw_circle(x, y):
t = Turtle()
t.penup()
t.goto(x, y)
t.pendown()
t.circle(50)
screen = Screen()
screen.onclick(draw_circle)
7. onkey(fun, key):当按下键盘上的特定键时调用指定的函数。例如:
python
from turtle import Screen, Turtle
def draw_circle():
t = Turtle()
t.circle(50)
screen = Screen()
screen.onkey(draw_circle, "c")
screen.listen() # 开启监听
这些方法和函数只是PythonTurtleScreen/Screen对象中的一部分,还有其他很多可以探索。
PythonTurtle是一个Turtle图形库,可以在Python中创建简单的图形并进行可视化编程。其中,PythonTurtleScreen/Screen对象提供了许多方法和函数来操作绘图界面。
1. screensize():设置绘图窗口的大小(像素)。例如:
python
from turtle import Screen
screen = Screen()
screen.screensize(500, 500)
2. bgcolor(color):设置绘图窗口的背景色。例如:
python
from turtle import Screen
screen = Screen()
screen.bgcolor("lightblue")
3. title(titlestring):设置绘图窗口的标题。例如:
python
from turtle import Screen
screen = Screen()
screen.title("My Turtle Drawing")
4. setup(width, height, startx, starty):设置绘图窗口的大小和位置。例如:
python
from turtle import Screen
screen = Screen()
screen.setup(500, 500, 0, 0)
5. exitonclick():点击关闭按钮后退出程序。例如:
python
from turtle import Screen
screen = Screen()
# do some drawing here
screen.exitonclick()
6. onclick(fun, btn=1, add=None):当鼠标在窗口内单击时调用指定的函数。例如:
python
from turtle import Screen, Turtle
def draw_circle(x, y):
t = Turtle()
t.penup()
t.goto(x, y)
t.pendown()
t.circle(50)
screen = Screen()
screen.onclick(draw_circle)
7. onkey(fun, key):当按下键盘上的特定键时调用指定的函数。例如:
python
from turtle import Screen, Turtle
def draw_circle():
t = Turtle()
t.circle(50)
screen = Screen()
screen.onkey(draw_circle, "c")
screen.listen() # 开启监听
这些方法和函数只是PythonTurtleScreen/Screen对象中的一部分,还有其他很多可以探索。
本文地址:
/show-276363.html
版权声明:除非特别标注原创,其它均来自互联网,转载时请以链接形式注明文章出处。