Okay, here's a simple Python script using the pygame library. Pygame is excellent for this kind of graphical display and input handling.
First, you'll need to install Pygame if you haven't already:
pip install pygame
Then, you can run this code:
python
import pygame
# 1. Initialize Pygame
pygame.init()
# --- Configuration ---
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
TEXT_COLOR = (255, 255, 255) # White
BACKGROUND_COLOR = (0, 0, 0) # Black
AT_SIGN = "@"
FONT_SIZE = 80 # Make the @ large and visible
MOVEMENT_SPEED = 5 # Pixels per key press
# 2. Set up the screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Movable @ Sign")
# 3. Prepare the text
font = pygame.font.SysFont("monospace", FONT_SIZE) # You can try different fonts like "Arial"
at_surface = font.render(AT_SIGN, True, TEXT_COLOR) # Render the @ sign
at_rect = at_surface.get_rect() # Get its rectangular bounds
# 4. Position the @ sign in the middle of the screen
at_rect.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
# 5. Game loop (where everything happens)
running = True
while running:
# --- Event Handling ---
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False # Stop the loop if the user closes the window
elif event.type == pygame.KEYDOWN:
# Check which arrow key was pressed
if event.key == pygame.K_LEFT:
at_rect.x -= MOVEMENT_SPEED
elif event.key == pygame.K_RIGHT:
at_rect.x += MOVEMENT_SPEED
elif event.key == pygame.K_UP:
at_rect.y -= MOVEMENT_SPEED
elif event.key == pygame.K_DOWN:
at_rect.y += MOVEMENT_SPEED
# Optional: Keep the @ sign within screen bounds
at_rect.left = max(0, at_rect.left)
at_rect.right = min(SCREEN_WIDTH, at_rect.right)
at_rect.top = max(0, at_rect.top)
at_rect.bottom = min(SCREEN_HEIGHT, at_rect.bottom)
# --- Drawing ---
screen.fill(BACKGROUND_COLOR) # Clear the screen with black
screen.blit(at_surface, at_rect) # Draw the @ sign at its current position
# --- Update Display ---
pygame.display.flip() # Or pygame.display.update()
# 6. Quit Pygame
pygame.quit()
How to run it:
- Save the code in a file named
movable_at.py (or any other .py extension).
- Open a terminal or command prompt.
- Navigate to the directory where you saved the file.
- Run the script using:
python movable_at.py
You will see a black window with a large white "@" sign in the center. Use your arrow keys to move it around!