This question already has answers here:
Unable to install pygame on Python via pip (Windows 10)
(6 answers)
Pygame 1.9.6 not loading in Python 3.8.1 [duplicate]
(1 answer)
Pygame not showing anything in the window [duplicate]
(2 answers)
Closed 2 years ago.
I have a MacOS Catalina 10.15.4 and Python 3.8.1. I finally got pygame 1.9.6 to install through the terminal with homebrew,xcode,and xquartz downloaded and imported it in my program. I'm a student and following instructions for a project so all the code has already been provided to me and says that a pygame window should show up. When I run the Python icon on my dock bounces up and down and it prints in the shell "Game console initialized
pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html". I've tried to read and mess around with what versions work with what but I'm pretty lost to what else I should be doing. Thanks for the help!
Here is my code:
print("Game console initialized")
import pygame
pygame.init()
screenSize = width,height = 240,180
display = pygame.display.set_mode(screenSize)
starImage = pygame.image.load("star.gif")
starBox = starImage.get_rect()
speed = [3,5]
keepPlaying = True
while keepPlaying:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepPlaying = False
starBox = starBox.move(speed)
if starBox.left<0 or starBox.right > width:
speed[0] = - speed[0]
if starBox.top <0 or starBox.bottom > height:
speed[1] = - speed[1]
black = 0,0,0
display.fill(black)
display.blit(starImage, starBox)
pygame.display.flip()
pygame.time.delay(100)
pygame.display.quit()
pygame.quit()
Related
This question already has answers here:
Why is my PyGame application not running at all?
(2 answers)
Closed 1 year ago.
on my mac I ran pygame and never got it working and I've done my research and found no conclusion.
The code I used to bring up some sort of screen...
import pygame
from pygame.locals import *
pygame.init()
win = pygame.display.set_mode((400,400))
pygame.display.set_caption("My first game")
clock = pygame.time.Clock()
run = True
while run:
# handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# update game objects
# [...]
# clear display
win.fill((0, 0, 0))
# draw game objects
# [...]
# update display
pygame.display.flip()
# limit frames per second
clock.tick(60)
pygame.quit()
The python launcher logo jumps up and down for a second
and comes up with python quit unexepctedly
Process: Python [4082]
Path: /Library/Frameworks
/Python.framework/Versions/3.9/Resources/Python.app
/Contents/MacOS/Python
Identifier: org.python.python
Version: 3.9.5 (3.9.5)
Code Type: X86-64 (Native)
Parent Process: Python [4040]
Responsible: Python [4082]
User ID: 505
Any help on how I can get pygame to work?
Or how to get any screen at all?
btw i installed pygame with pip3
and pip
You aren't telling pygame to run any events, and so the window just closes and the program stops.
This question already has answers here:
Why is my PyGame application not running at all?
(2 answers)
Why is nothing drawn in PyGame at all?
(2 answers)
Closed 2 years ago.
i have no problem of syntax or any erorr its just a problems when i run the program
import pygame
pygame.init()
# generate window
pygame.display.set_caption("shooter Game")
pygame.display.set_mode((1080, 720))
running = True
while running:
# if the player close the window
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
print("game closed")
sceenshot of the code and the 🚀 of python that not stoping to jump
You don't update the display, which you have to do with
pygame.display.update()
You can add it right after pygame.display.set_mode((1080, 720))
Try like this and tell me if it works :)
I am just learning how to use pygame.
But whenever I run the code, it doesn't run but a python rocket appears and starts bouncing.
The only thing I can do on the rocket is force quit.
My python is 3.8.2 and pygame is 1.9.6, on my mac, if it helps.
This is the code I'm trying to run, just a basic set up code:
import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("First Game")
x = 50
y = 50
width = 40
height = 60
vel = 5
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
pygame.display.update()
pygame.quit()
I just ran your code using python 3.7 on a macbook Mojave and I just got a red rectangle (like your code specifies) in one position. Possibly try restarting your computer, checking you version of python, or renaming the file (originally I named the file pygame and it was giving me a bunch of issues) to make it run the correct thing.
Jubin- I just ran your code on Mac and it works. I think the trouble is that IDLE won't allow it to run for some reason.
Try running it from the command line using Terminal app. It runs fine for me doing that, but will not run from IDLE.
Open Terminal
Navigate your way to the folder that contains your file
Type "python filename.py"
This question already has answers here:
Problems getting pygame to show anything but a blank screen on Macos
(10 answers)
pygame installation issue in mac os
(5 answers)
Closed 2 years ago.
I wanted to blit an image in python, a png image. But for some reason about half the image has the wrong pixel colours, it looks all messy, having random coloured pixels in it. I have made a few games on my Macbook Pro (OSX) using pygame with python 3.4, and I had no trouble when it came to blitting images. Here's the code:
import pygame
import os
w = pygame.display.set_mode((300,300))
bug = os.path.join("/Users/Snyman/Desktop/images/double-block_spm_R.png")
bug = pygame.image.load(bug).convert_alpha()
bug = pygame.transform.scale(bug,(64,64))
loop = True
while loop:
for event in pygame.event.get():
if event.type == pygame.QUIT:
loop = False
w.fill((255,255,255))
w.blit(bug,(10,10))
pygame.display.update()
pygame.quit()
"bug" is my image
This question already has answers here:
What is the difference between .quit and .QUIT in pygame
(2 answers)
pygame window closes immediatly after opening up
(1 answer)
Closed 1 year ago.
I have used Pygame with python 2.7 before but recently I 'upgraded' to python 3.2. I downloaded and installed the newest version of Pygame which is said to work with this version of python. I have, however, had this rather frustrating error on what should be a simple block of code. The code is:
import pygame, random
title = "Hello!"
width = 640
height = 400
pygame.init()
screen = pygame.display.set_mode((width, height))
running = True
clock = pygame.time.Clock()
pygame.display.set_caption(title)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.quit():
running = False
else:
print(event.type)
clock.tick(240)
pygame.quit()
And every single time I run it I get:
17
1
4
Traceback (most recent call last):
File "C:/Users/David/Desktop/hjdfhksdf.py", line 15, in <module>
for event in pygame.event.get():
pygame.error: video system not initialized
Why am I getting this error?
if event.type == pygame.quit():
In the line above, you're calling pygame.quit() which is a function, while what you really want is the constant pygame.QUIT. By calling pygame.quit(), pygame is no longer initialized, which is why you get that error.
Thus, changing the line to:
if event.type == pygame.QUIT: # Note the capitalization
Will solve your problem.
It's important to note that pygame.quit() will not exit the program.