【发布时间】:2021-03-02 04:27:16
【问题描述】:
import pygame, sys
pygame.init()
clock = pygame.time.Clock()
coordinate = pygame.mouse.get_pos()
screen = pygame.display.set_mode((1000,800), 0, 32)
pygame.display.set_caption("Mouse Tracker")
font = pygame.font.Font(None, 25)
text = font.render(coordinate, True, (255,255,255))
while True:
screen.fill((0,0,0))
screen.blit(text, (10, 10))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
clock.tick(60)
我正在尝试制作一个程序来跟踪您的鼠标并在屏幕上显示它的坐标。我收到一条错误消息: text = font.render(坐标, True, (255,255,255)) TypeError:文本必须是 unicode 或字节。 我正在使用 Python 3.9.1
【问题讨论】:
标签: python pygame mouse tracking