【问题标题】:How to draw a circle in PyGame?如何在 PyGame 中画一个圆?
【发布时间】:2017-10-20 07:01:51
【问题描述】:

您好,我在绘制圆圈 ERROR: module object has no attribute 'circle' 时遇到问题。我做错了什么?

还有我怎样才能把数字放在圆圈里?

例如:(第一次点击是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.circle(screen, BLUE, pos, 20)


if __name__ == '__main__':
    main()

【问题讨论】:

    标签: python pygame draw


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      下面是在pygame中画圆的方法;

      import pygame
      pygame.init()
      screen = pygame.display.set_mode((x, y)) #x and y are height and width
      
      pygame.draw.circle(screen, (r,g,b), (x, y), R, w) #(r, g, b) is color, (x, y) is center, R is radius and w is the thickness of the circle border.
      

      【讨论】:

        【解决方案3】:

        以下是正确绘制圆圈的方法

        import pygame
        
        window = pygame.display.set_mode((500,500))
        red = (200,0,0)
        
        circleX = 100
        circleY = 100
        radius = 10
        
        active = True
        
        while active:
           for event in pygame.event.get():
              if event.type == pygame.QUIT:
                 active = False
        
           pygame.draw.circle(window,red,(circleX,circleY),radius) # DRAW CIRCLE
        
           pygame.display.update()
        

        【讨论】:

          【解决方案4】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-11-12
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-11-12
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多