python - 我想使用 pyglet 在新窗口中显示五个数字
问题描述
我一直在尝试每秒显示从 0 到 4 的五个数字。
import pyglet
import time
window = pyglet.window.Window()
@window.event
def on_draw():
for n in range(0,5):
window.clear()
label = pyglet.text.Label(str(n),font_name='Times New Roman',font_size=72,x=window.width//2, y=window.height//2,anchor_x='center', anchor_y='center')
label.draw()
print(n)
time.sleep(1)
pyglet.app.run()
它没有遇到任何错误,尽管它是一个空白屏幕几秒钟,之后它只显示第四个。
解决方案
我将从文档开始并查看简单的文本示例。
https://pyglet.readthedocs.io/en/latest/programming_guide/text.html
on_draw
没有被正确使用。
然后对于每 1 秒的调度更改,请查看时钟调度示例。
https://pyglet.readthedocs.io/en/latest/modules/clock.html#scheduling
推荐阅读
- python - Python调试器找不到模块
- c - eBPF:如何从 `struct __sk_buff` 中获取与 sock 关联的套接字
- postgresql - 使用 docker-compose 时出现 Postgres 数据库连接问题
- node.js - 从 Node.js 脚本执行子进程,并将完整的输入和输出转发给它
- angular - 在 Angular 项目中需要一个 dojo 模块
- django - “用户”对象没有属性“is_staff”
- python - 在python中将json文件时间戳格式更改为日期时间的函数
- javascript - “Z”之前的值在 ISO8601 日期字符串中表示什么?
- bash - 如何通过关机触发systemd服务运行shell脚本,暂停直到脚本完成
- r - 在 r 中创建相同大小的循环中的空数据帧并给它们另一个数据帧的列名?