turtle 模块以面向对象和面向过程的方式提供 turtle 图形基元。由于它使用tkinter作为基础图形,因此需要安装有Tk支持的Python版本。
turtle .onrelease()
此函数用于将乐趣绑定到画布上此 turtle 上的mouse-button-release事件。
用法:
turtle.onrelease(fun, btn=1, add=None)
参数:
参数 | 描述 |
fun | 一个带有两个参数的函数,在画布上单击点的坐标将分配给该函数。 |
btn | mouse-button的编号默认为1(鼠标左键)。 |
add | 对或错。如果为True,将添加新的绑定,否则,它将替换以前的绑定 |
下面是上述方法的实现示例:
Python3
# import package
import turtle
# methods to action
def fxn1(x,y):
turtle.fillcolor("blue")
def fxn2(x,y):
turtle.fillcolor("white")
# set screen and turtle
sc=turtle.Screen()
sc.setup(400,300)
turtle.shape("turtle")
turtle.turtlesize(2)
turtle.speed(1)
# allow user to click for some action
turtle.onclick(fxn1)
# allow user to release for some action
turtle.onrelease(fxn2)
输出:
在这里我们可以找到:
- 每当用户单击 turtle (箭头上的yellow-colored点)时,它就会变为蓝色,并且
- 从屏幕上释放(黄点消失)后,它变为白色。
相关用法
- Python Wand function()用法及代码示例
- Python tell()用法及代码示例
- Python id()用法及代码示例
- Python map()用法及代码示例
- Python dir()用法及代码示例
- Python cmp()用法及代码示例
- Python int()用法及代码示例
- Python ord()用法及代码示例
- Python hex()用法及代码示例
- Python now()用法及代码示例
- Python oct()用法及代码示例
- Python str()用法及代码示例
- Python sum()用法及代码示例
- Python seek()用法及代码示例
- Python reversed()用法及代码示例
注:本文由纯净天空筛选整理自deepanshu_rustagi大神的英文原创作品 turtle.onrelease() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。