macos - 在 pygame 中打印 Pyautogui 命令
问题描述
我目前正在尝试制作一个 pyautogui/pygame 代码来跟踪鼠标位置并在 pygame 窗口上打印绳索。这是我到目前为止所拥有的:
import pygame
import pygame.freetype
import pyautogui
import time
pygame.init()
POS = pyautogui.position()
screen = pygame.display.set_mode((800, 600))
GAME_FONT = pygame.freetype.Font("/Users/user/Desktop/Calibri.ttf", 24)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((255, 255, 255))
while True:
time.sleep(0.4)
GAME_FONT.render_to(screen, (40, 350), POS, (0, 0, 0))
pass
pygame.display.flip()
pygame.quit()
当我运行此代码时,我收到错误:
TypeError: Expected a Unicode or LATIN1 (bytes) string for text: got type Point
如您所见,变量 POS 包含命令;我想在我的 pygame 屏幕上打印命令输出。有没有其他选择,或者我只是看错了?我在网上搜索过,在这里问一个问题通常是我最后的手段,所以:感谢任何帮助/批评。
解决方案
first if POS is not a static variable, you should put its name in lowercase since uppercase us used for static ones. Next, you are trying to print a point type variable since pyautogui.position() returns the mouse coordinates. You should try casting it into a string: POS = str(POS)
推荐阅读
- javascript - 选择列表显示键而不是值
- oracle-apex - 在 Oracle APEX 19.2 中增加最大 Web 服务请求
- c# - AspNet CORE - EF 多对多与连接表在同一个表上
- file - 请求文件列表时仅引发一次 Curl 回调
- javascript - 调用堆栈为空时是否会执行 node.js 事件的处理程序?
- python - Configure Python Flask RESTplus app via TOML file
- python - 如何在 django 中根据文件类型显示视频或图像
- angular - @Viewchild 在角度 7 中具有多个自动完成 ID
- c# - .net http webclient to nodejs server. How to access data?
- php - PHP - How to process/save weekly files