小编Aik*_*o42的帖子

Python Pyglet鼠标事件不调用on_draw()也不在窗口中进行更改

由于某种原因,尽管我的on_key_press()功能可以正常工作,但我的程序发生的任何鼠标事件都不会使窗口中的图像消失或重新出现。

我已经尝试过状态标志并声明新的图像资源,但是它不会更改窗口中的任何内容。

有没有办法使这项工作?我应该还原到以前的pyglet版本吗?如果是这样,哪个版本?

这是我的程序代码;它在测试图像可见的情况下运行,并且每按一次键或单击鼠标,图像就会消失或重新出现:

import pyglet

window = pyglet.window.Window()

image = pyglet.resource.image('test.png')
image.anchor_x = image.width // 2
image.anchor_y = image.height // 2

state = True


@window.event
def on_draw():
    print('on_draw() called')
    window.clear()
    if state:
        image.blit(window.width // 2, window.height // 2)


@window.event
def on_mouse_press(x, y, button, modifiers):
    global state, image
    if button == pyglet.window.mouse.LEFT:
        print('mouse press')
        if state:
            state = False
        else:
            state = True


@window.event
def on_key_press(symbol, modifiers):
    global state
    print('key press')
    if state:
        state = False
    else:
        state …
Run Code Online (Sandbox Code Playgroud)

python pyglet python-3.x

6
推荐指数
1
解决办法
43
查看次数

标签 统计

pyglet ×1

python ×1

python-3.x ×1