Python 如何在 PyGame 中画一个圆圈?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46843897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:52:46  来源:igfitidea点击:

How to draw a circle in PyGame?

pythonpygamedraw

提问by Tuff

Hi I am having a problem with drawing a circle ERROR: module object has no attribute 'circle'. what am I doing wrong?

嗨,我在画圆时遇到问题ERROR: module object has no attribute 'circle'。我究竟做错了什么?

And also how can I put numbers in circles?

还有我怎样才能把数字圈起来?

For example: (first click is circle with 0 second is circle with 1 and so on)

例如:(第一次点击是0的圆圈,第二次是1的圆圈等等)

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()

回答by Ericson Willians

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

您输入了错误的函数名称。正确的名称是pygame.draw.circle

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

回答by Arijit Sur

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

为你画的圆的数量维护一个计数器,并用与圆心相同的坐标写下数字。该命令也是 pygame.draw.circle 而不是 pygame.draw.circl