With pygame it would look something like this:
import pygame
SCREEN = pygame.display.set_mode ((600, 400))
circle_x = 50
step = .4
while True :
for event in pygame.event.get () :
if event.type == pygame.QUIT :
quit ()
SCREEN.fill ((0, 0, 0))
pygame.draw.rect (SCREEN, (0, 0, 250), (50, 200, 500, 10))
circle_x += step
if circle_x > 500 or circle_x < 50 :
step = -step
pygame.draw.ellipse (SCREEN, (255, 0, 0), (circle_x, 150, 50, 50))
pygame.display.update ()
Or are you using tkinter or turtle or what ?