2025-03-10 18:31:39 +08:00

53 lines
1.6 KiB
Python

import pygame
def selector():
pygame.init()
try:
width = int(input("Frame Width: "))
height = int(input("Frame Height: "))
except:
width = 800
height = 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("UI Design Auxiliary Tool")
selecting = False
start_pos = None
end_pos = None
running = True
screen.fill((0,0,0))
while running:
screen.fill((0,0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1: # 左键
selecting = True
start_pos = event.pos
elif event.type == pygame.MOUSEMOTION:
if selecting:
end_pos = event.pos
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
selecting = False
if start_pos and end_pos:
rect = pygame.Rect(
start_pos,
(end_pos[0] - start_pos[0], end_pos[1] - start_pos[1]),
)
if selecting and start_pos and end_pos:
rect = pygame.Rect(
start_pos, (end_pos[0] - start_pos[0], end_pos[1] - start_pos[1])
)
pygame.draw.rect(screen, (255, 0, 0), rect, 2) # 绘制选区矩形
pygame.display.flip()
pygame.quit()
if __name__ == "__main__":
main()