天天看點

python中畫圓的代碼_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建立界面并監控鼠2113标5261按下事件,獲得按下位置,畫4102圓

代碼注意縮進如下圖:1653

python中畫圓的代碼_python 繪制一個圓,當單擊視窗的任意位置時圓移動到單擊的位置,如何編寫代碼?...
python中畫圓的代碼_python 繪制一個圓,當單擊視窗的任意位置時圓移動到單擊的位置,如何編寫代碼?...