import pygame
import datetime
with open('textdatei.txt', 'a') as file:
pygame.init()
print("Start: " + str(datetime.datetime.now()), file=file)
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
BG_COLOR = pygame.Color('gray12')
done = False
while not done:
# This event loop empties the event queue each frame.
for event in pygame.event.get():
# Quit by pressing the X button of the window.
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.MOUSEBUTTONDOWN:
# MOUSEBUTTONDOWN events have a pos and a button attribute
# which you can use as well. This will be printed once per
# event / mouse click.
print('In the event loop:', event.pos, event.button)
print("Maus wurde geklickt: " + str(datetime.datetime.now()), file=file)
# Instead of the event loop above you could also call pygame.event.pump
# each frame to prevent the window from freezing. Comment it out to check it.
# pygame.event.pump()
click = pygame.mouse.get_pressed()
mousex, mousey = pygame.mouse.get_pos()
print(click, mousex, mousey, file=file)
screen.fill(BG_COLOR)
pygame.display.flip()
clock.tick(60) # Limit the frame rate to 60 FPS.
print("Ende: " + str(datetime.datetime.now()), file=file)
你好,我是Pygame的新手,目前我的程序可以跟踪鼠标坐标并记录点击时间。但我想要计算鼠标从一个点击到下一个点击的速度(以像素每秒为单位)。
提前感谢。