【发布时间】:2020-10-11 12:18:07
【问题描述】:
我目前正在尝试制作一个 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 屏幕上打印命令输出。有没有其他选择,或者我只是看错了?我在网上搜索过,在这里问一个问题通常是我最后的手段,所以:感谢任何帮助/批评。
【问题讨论】:
标签: macos pygame python-3.7 pyautogui