First use of Pygame on Mac (stuck)

Source: Internet
Author: User

First use Pygame to achieve the drawing function on the pit

Directly on the code

Import Pygame

Pygame.init ()

# Create a game window 480 *
Screen = Pygame.display.set_mode ((480,.))

# Draw a background image
# 1> loading image data
bg = pygame.image.load ("./images/background.png")
# 2> Blit drawing Images
screen.blit (BG, (0, 0))
# 3> Update screen display
pygame.display.update ()

While True:
Pass

pygame.quit ()

This code runs on Linux and Windows, but it's stuck in the Mac system.

Very headache, I want to appear the most likely because of the infinite loop caused by, so, I put the Loop code deleted. Rerun to see the drawn picture flashed past.

Then the problem must be in the loop.

So I took the "run Pygame appear stuck" problem, on the Internet to see such a piece of code

While True:
event = Pygame.event.poll ()
if Event.type = = Pygame. QUIT:
Pygame.quit ()
Exit ()

When I copy and paste this code, a miracle appears. The drawing window is working correctly.

For those who know the reason, please do not hesitate to enlighten

First use of Pygame on Mac (stuck)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.