'"Hello from the pygame community"
When I executed the following code, instead of an error it said "Hello from the pygame community. https://www.pygame.org/contribute.html". It would be easier for me if it just included the error so I could fix it myself without posting the code in stackoverflow (for privacy reasons).
Here's the code:
# import the pygame module, so you can use it
import pygame
# define a main function
def main():
# initialize the pygame module
pygame.init()
# load and set the logo
logo = pygame.image.load("logo32x32.png")
pygame.display.set_icon(logo)
pygame.display.set_caption("minimal program")
# create a surface on screen that has the size of 240 x 180
screen = pygame.display.set_mode((240, 180))
# define a variable to control the main loop
running = True
# main loop
while running:
# event handling, gets all event from the eventqueue
for event in pygame.event.get():
# only do something if the event is of type QUIT
if event.type == pygame.QUIT:
# change the value to False, to exit the main loop
running = False
# draw a green line from (0,0) to (100,100)
pygame.draw.line(screen, (0,255,0), (0,0), (100,100))
# draw a green line from (0,100) to (100,0)
pygame.draw.line(screen, (0,255,0), (0,100), (100,0))
# draw a rectangle outline
pygame.draw.rect(screen, (0,255,0), (60,60,100,50), 1)
# draw a filled in rectangle
pygame.draw.rect(screen, (0,255,0), (60,120,100,50))
# draw a circle
pygame.draw.circle(screen, (0,255,0), (120,60), 20, 0)
# draw a circle outline
pygame.draw.circle(screen, (0,255,0), (120,60), 20, 1)
# draw a polygon
pygame.draw.polygon(screen, (0,255,0), ((140,60),(160,80),(160,100),(140,120),(120,100),(120,80)), 0)
# draw a filled in poly
pygame.draw.polygon(screen, (0,255,0), ((140,60),(160,80),(160,100),(140,120),(120,100),(120,80)), 1)
# draw a text
font = pygame.font.Font(None, 36)
text = font.render("Hello There", 1, (10, 10, 10))
textpos = text.get_rect()
textpos.centerx = screen.get_rect().centerx
screen.blit(text, textpos)
# update the screen
pygame.display.flip()
# quit pygame properly to clean up resources
pygame.quit()
# end of the code
Solution 1:[1]
That isn't an error. That line is printed when you import pygame. None of your code is producing an error because none of it is being called. After you define the main function, make sure to call main().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Zachary Milner |