[Python] Rect not working with screen.draw.filled_rect in pygame zero

Discussão em 'Python' iniciado por Stack, Março 2, 2025.

  1. Stack

    Stack Membro Participativo

    Right now i am coding a pygame zero program It is at its first steps and i am trying to make the play button why isn't it drawing? I am using screen.draw.filled_rect(text, rect, kwaargs**)

    Here is my code

    import pgzrun
    def draw():
    global x, play_button
    screen.clear()
    screen.blit('actualbg', (0, 0))
    #screen.fill((128, 0, 0))
    if first_screen:
    screen.draw.text('Marvel run', center=(370, 100), fontname='impact', fontsize = 100, color="orange", owidth=1)
    screen.draw.filled_rect(play_button, 'yellow')
    screen.draw.textbox('Play', play_button, fo1ntname='impact', color='black')

    #to be continued

    WIDTH = 800
    HEIGHT = 590
    first_screen = True
    play_screen = False
    option_screen = False
    play_button = Rect(100, 50)

    play_button.midtop=(0, 0)
    play_button.move_ip(383, 266)
    first_screen = True
    play_screen = False
    option_screen = False

    pgzrun.go()



    I have looked at so many websites but they are no help:(

    I ran it and it came up with


    File "marvel.py", line 21, in <module>
    play_button = Rect(100, 50)
    ^^^^^^^^^^^^^
    TypeError: Argument must be rect style object


    It was supposed to create a yellow rectangle with text inside it and the rectangle is filled Thanks

    Continue reading...

Compartilhe esta Página