How to draw a circle in PyGame?

*爱你&永不变心* 提交于 2020-03-23 08:06:52

问题


Hi i am haveing some problem with drawing a circle ERROR: "'module' object has no attribute 'circl'" what am I dooing wrong?

And also how can I put numbers in circles? ex: (first click is circle with 0 second is circle with 1 and so on)

import pygame

WHITE =     (255, 255, 255)
BLUE =      (  0,   0, 255)
GREEN =     (  0, 255,   0)
RED =       (255,   0,   0)
TEXTCOLOR = (  0,   0,  0)
(width, height) = (200, 300)

running = True

def main():
    global running, screen

    pygame.init()
    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption("TUFF")
    screen.fill(background_color)
    pygame.display.update()

    while running:
        ev = pygame.event.get()

        for event in ev:

            if event.type == pygame.MOUSEBUTTONUP:
                drawCircle()
                pygame.display.update()

            if event.type == pygame.QUIT:
                running = False

def getPos():
    pos = pygame.mouse.get_pos()
    return (pos)

def drawCircle():
    pos=getPos()
    pygame.draw.circl(screen, BLUE, pos, 20)


if __name__ == '__main__':
    main()

回答1:


You've mistyped the name of the function. The correct name is pygame.draw.circle.

def drawCircle():
    pos=getPos()
    pygame.draw.circle(screen, BLUE, pos, 20) # Here <<<



回答2:


Mainter a counter for the number of circles you have drawn and write the number with the co-ordinates same as the centre of the circle. Also the command is pygame.draw.circle and not pygame.draw.circl



来源:https://stackoverflow.com/questions/46843897/how-to-draw-a-circle-in-pygame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!