如何在PyGame中画一个圆?

2024-06-02 07:30:29 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我在画一个圆时遇到了一些问题:“module”对象没有“circl”属性。我画错什么了?

我怎样才能把数字圈起来呢? 例:(第一次单击是带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()

Tags: poseventifmaindefdisplayupdateblue
2条回答

你把函数名打错了。正确的名称是pygame.draw.circle

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

为你画的圆的数目输入一个计数器,并用与圆的中心相同的坐标写出数字。 命令也是pygame.draw.circle而不是pygame.draw.circl

相关问题 更多 >