pygame.mouse.get_visible() 失败
pygame.mouse.get_visible() Fails
我编写了一个方便的屏幕键盘模块,当我在我的 PC 上以平板电脑模式编写程序时可以导入和使用该模块。运行。因为我想在以后的许多程序中导入和使用这个实用程序,所以我想在模块开始时存储当前鼠标位置和鼠标可见性状态,然后在模块退出时恢复这些条件。 .mouse.get_pos() 命令工作得很好,但是.mouse.get_visible() 命令失败了,返回错误信息:AttributeError: module 'pygame.mouse' has no attribute 'get_visible' 的pygame 鼠标文档将此列为有效方法 (https://www.pygame.org/docs/ref/mouse.html),我没有看到任何迹象表明它已被贬低或删除。
这是一个演示问题的示例程序:
import pygame
from time import sleep
pygame.init()
screen = pygame.display.set_mode((3000,2000),pygame.FULLSCREEN)
screen.fill(pygame.Color("lightblue"))
pygame.display.flip()
pygame.mouse.set_visible(True)
print("\n pygame.mouse.get_pos() returned >>",pygame.mouse.get_pos())
try:
print(" pygame.mouse.get_visible() returned >>",pygame.mouse.get_visible())
except:
print(" pygame.mouse.get_visible() failed!")
print()
sleep(0.5)
pygame.quit()
接受的回复将回答以下一个或两个问题:
1.) 是这种方法 broken/missing,还是我遗漏了一些明显的东西?
2.) 有没有人对我如何在没有 get_visible() 方法的情况下获得可见性状态有任何建议,以便我可以在离开键盘模块之前恢复状态?
pygame.mouse.set_visible
在旧的 PyGame 版本中被破坏。更新 Pygame 到最新版本。
在某些系统上,需要在鼠标指针的更改生效之前处理事件:
pygame.mouse.set_visible(True)
print(" pygame.mouse.get_pos() returned >>",pygame.mouse.get_pos())
pygame.event.pump()
try:
print(pygame.mouse.get_visible())
except:
print(" pygame.mouse.get_visible() failed!")
参见pygame.event.get()
respectively pygame.event.pump()
:
For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.
我编写了一个方便的屏幕键盘模块,当我在我的 PC 上以平板电脑模式编写程序时可以导入和使用该模块。运行。因为我想在以后的许多程序中导入和使用这个实用程序,所以我想在模块开始时存储当前鼠标位置和鼠标可见性状态,然后在模块退出时恢复这些条件。 .mouse.get_pos() 命令工作得很好,但是.mouse.get_visible() 命令失败了,返回错误信息:AttributeError: module 'pygame.mouse' has no attribute 'get_visible' 的pygame 鼠标文档将此列为有效方法 (https://www.pygame.org/docs/ref/mouse.html),我没有看到任何迹象表明它已被贬低或删除。
这是一个演示问题的示例程序:
import pygame
from time import sleep
pygame.init()
screen = pygame.display.set_mode((3000,2000),pygame.FULLSCREEN)
screen.fill(pygame.Color("lightblue"))
pygame.display.flip()
pygame.mouse.set_visible(True)
print("\n pygame.mouse.get_pos() returned >>",pygame.mouse.get_pos())
try:
print(" pygame.mouse.get_visible() returned >>",pygame.mouse.get_visible())
except:
print(" pygame.mouse.get_visible() failed!")
print()
sleep(0.5)
pygame.quit()
接受的回复将回答以下一个或两个问题:
1.) 是这种方法 broken/missing,还是我遗漏了一些明显的东西?
2.) 有没有人对我如何在没有 get_visible() 方法的情况下获得可见性状态有任何建议,以便我可以在离开键盘模块之前恢复状态?
pygame.mouse.set_visible
在旧的 PyGame 版本中被破坏。更新 Pygame 到最新版本。
在某些系统上,需要在鼠标指针的更改生效之前处理事件:
pygame.mouse.set_visible(True)
print(" pygame.mouse.get_pos() returned >>",pygame.mouse.get_pos())
pygame.event.pump()
try:
print(pygame.mouse.get_visible())
except:
print(" pygame.mouse.get_visible() failed!")
参见pygame.event.get()
respectively pygame.event.pump()
:
For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.