Error in user YAML: (<unknown>): found a tab character that violate indentation while scanning a plain scalar at line 3 column 3
---
- oeasy Python 0649
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
- 本教程同步发布在:
- 个人网站: `https://oeasy.org`
- 蓝桥云课: `https://www.lanqiao.cn/courses/3584`
- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial`
- Gitee: `https://gitee.com/overmind1980/oeasypython`
---- 上次研究了鼠标的各种互动效果
- 键盘可以有什么互动效果吗??🤔
import cv2
import numpy as np
canvas = np.zeros((300,300,3),np.uint8)
cv2.imshow("win",canvas)
while True:
key = cv2.waitKey(0)
cv2.putText(canvas,chr(key),(30,80),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
cv2.imshow("win",canvas)
- 如果按下F1
- 需要将输出的字符序号限制在ascii范围(0-127)
- 如果按F1
- 就退出
- 如果在ascii范围内
- 就输出
import cv2
import numpy as np
canvas = np.zeros((300,300,3),np.uint8)
cv2.imshow("win",canvas)
while True:
key = cv2.waitKey(0)
if key == ord("q"):
break
if 0 < key < 127:
cv2.putText(canvas,chr(key),(30,80),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
cv2.imshow("win",canvas)
- 键盘输入字符
- 可以将字形输出到终端频幕上
- 可以输入一个字符平移一下吗?
import cv2
import numpy as np
canvas = np.zeros((300,300,3),np.uint8)
x = 80
dx = 0
cv2.imshow("win",canvas)
while True:
key = cv2.waitKey(0)
if key == ord("q"):
break
if 0 < key < 127:
cv2.putText(canvas,chr(key),(x + dx,30),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
cv2.imshow("win",canvas)
dx = dx + 40
- 效果
- 如果超过5个字符 可以添加还行特效吗?
import cv2
import numpy as np
canvas = np.zeros((300,300,3),np.uint8)
x = 40
dx = 40
y = 60
dy = 40
cv2.imshow("win",canvas)
while True:
key = cv2.waitKey(0)
print(key)
if key == 13:
x = 40
y = y + dy
continue
if key == ord("q"):
break
if 0 < key < 127:
cv2.putText(canvas,chr(key),(x, y),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
cv2.imshow("win",canvas)
x = x + dx
- 执行效果
- 这次研究了键盘互动的效果
- 写字效果
- 感觉可以做一个打字练习器
- 下次玩点什么呢?🤔
- 下次再说👋
- 本文来自 oeasy Python 系统教程。
- 想完整、扎实学 Python,
- 搜索 oeasy 即可。



