如何在python中移动圆?

如何在python中移动圆?,python,pygame,Python,Pygame,我试图做一个可以移动的圆圈,但我不知道如何使它工作。我使用pygame作为包。我想如果你更新这个圆圈会有用的,但我不知道怎么做 import os, sys, math, pygame, pygame.mixer from pygame.locals import * black = (0,0,0) red = (255,0,0) green = (0,255,0) blue = (0,0,255) white = (255,255,255) run_me = True screen_siz

我试图做一个可以移动的圆圈,但我不知道如何使它工作。我使用pygame作为包。我想如果你更新这个圆圈会有用的,但我不知道怎么做

import os, sys, math, pygame, pygame.mixer
from pygame.locals import *

black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
white = (255,255,255)
run_me = True

screen_size = screen_width, screen_height = 600, 400
screen = pygame.display.set_mode(screen_size)
pygame.display.set_caption('ha ha ha ha ha')

clock = pygame.time.Clock()
fps_limit = 60

#circle 
    colorcircle = (red)
    posx = 300
    posy = 200
    circle = pygame.draw.circle(screen, colorcircle, (posx, posy), 50)

while run_me:
    clock.tick(fps_limit) 


    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run_me = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                posx = posx - 10
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                posx = posx + 10
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                posy = posy + 10
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_DOWN:
                posy = posy - 10

    pygame.display.flip()

pygame.quit()
我希望圆根据输入移动到某个位置


然而,圆圈什么也不做

要移动圆,必须每帧重新绘制一次。 为此,将以下内容添加到while循环中(就在
pygame.display.flip()之前)

# fill the screen with black (otherwise, the circle will leave a trail)
screen.fill(black)
# redraw the circle
pygame.draw.circle(screen, colorcircle, (posx, posy), 50)