python 绘制一个圆,当单击窗口的任意位置时圆移动到单击的位置,如何编写代码?
#-*- coding: UTF-8 -*-
import pygame, sys
from pygame.locals import *
white = 255, 255, 255
blue = 0, 0, 200
pygame.init()
screen = pygame.display.set_mode((600, 800))
myfont = pygame.font.Font(None, 20)
textImage = myfont.render("hello game", True, white)
position = 200, 200
print(position)
while True:
for event in pygame.event.get():
if event.type in (QUIT, KEYDOWN):
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
position = event.pos
screen.fill(blue)
screen.blit(textImage, (100, 100))
#position = 200, 200
radius = 100
width = 10
pygame.draw.circle(screen, white, position, radius, width)
pygame.display.update()
用pygame创建界面并监控鼠标按下事件,获得按下位置,画圆
代码注意缩进如下图: