Wrong fullscreen resolution with Pygame on OSX [duplicate] - python

I just started learning how to use Pygame earlier this week. While messing around with it I discovered that if I make a fullscreen window and leave it open for about 10 seconds and close it, all the other windows I have open will shrink in size and my screen is at a lower resolution for a few seconds.
These things happen with this chunk of code:
import pygame
pygame.init()
pygame.display.set_mode((500, 500),
pygame.FULLSCREEN)
running = True
while running is True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
Why would this code change the state of my other windows and change my screen resolution temporarily?
I am working with Pygame 2.0.1 with Python 3.9.1 using PyCharm 2020.3.1 on macOS Big Sur 11.1.

Change
pygame.display.set_mode((500, 500), pygame.FULLSCREEN)
to
pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
Pygame will automatically detect the screen size.

Related

Python Pygame after closing with pygame.quit() I can't open it again without stoping the whole script and restarting it

I want to close the Pygame-Window after a specific event occurred and open it again after another event occurred without stopping the whole script. When I stop pygame with pygame.quit() and want to register a font or do whatever it gives me an error that says that pygame is not initialized so I coded it so it would call pygame.init() again after it closed the pygame window but as I read here pygame thinks it is still initialized and when I call pygame.init() again it won't really do anything. I don't get the error anymore but the code gets stuck at that point where I want to use pygame again, after I closed the pygame window with pygame.quit() and initialized it again, and then after 2 seconds, it just stops the script. How can I prevent pygame from doing this and reopen the pygame window without restarting the script?
Thank you.
What you are looking for is pygame.display.quit()
the following script display a pygame window for 1 second then close it
import pygame
import time
pygame.display.set_mode((1024, 668))
time.sleep(1)
pygame.display.quit()
pygame.quit() is the counterpart of pygame.init(). Not what you're trying to do.

Pygame Won't Initialize Game Window on M1 MacBook Air [duplicate]

This question already has answers here:
What is the difference between .quit and .QUIT in pygame
(2 answers)
Closed 1 year ago.
I just bought an M1 MacBook Air today for coding a pygame project, but at very beginning I had an issue with pygame video system. it won't initialize pygame window. The following code snippet works in PC, but M1 Mac just won't initialize it. the error message I got is "pygame error: video system not initialize"
I am not sure if this issue is just for M1 Mac or it is an issue for all Mac users. Does anyone know the answer and solution for this error?
Thank you very much!
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.quit():
run = False
I initially thought this was an M1 mac problem, since pygame doesn't have good support for M1 mac yet.
However I see the problem:
if event.type == pygame.quit():
should be
if event.type == pygame.QUIT
Right now you're running the function pygame.quit(), which uninitializes your video system.

When I'm trying to run my pygame script I face problems [duplicate]

I'm learning how to use pygame, and I'm just trying to open up a window for the game I'm creating.
The program compiles fine, and I tried drawing a circle to see if that would change anything but in both scenarios I still just get a blank window that freezes. My computer has plenty of storage space and only 2 applications open, and yet this is the only application that is freezing.
import pygame
pygame.init()
window = pygame.display.set_mode((500, 500))
I have to force quit Python because it stops responding. I have Python version 3.7.4 and Pygame version 1.9.6.
Any advice?
A minimal, typical PyGame application
needs a game loop
has to handle the events, by either pygame.event.pump() or pygame.event.get().
has to update the Surface whuch represents the display respectively window, by either pygame.display.flip() or pygame.display.update().
See also Python Pygame Introduction
Simple example, which draws a red circle in the center of the window: repl.it/#Rabbid76/PyGame-MinimalApplicationLoop
import pygame
pygame.init()
window = pygame.display.set_mode((500, 500))
# main application loop
run = True
while run:
# event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# clear the display
window.fill(0)
# draw the scene
pygame.draw.circle(window, (255, 0, 0), (250, 250), 100)
# update the display
pygame.display.flip()

Pygame window not showing in MacOSX

I've been using pygame inside a conda environment. The installation went well, but whenever I call flip, it doesn't open any window from the terminal.
Here's the code that's supposed to open the window:
screen.blit(background_image, (0, 0))
pygame.display.flip()
pygame.display.update()
After pygame starts, it shows this message:
WARNING: 140: This application, or a library it uses, is using the
deprecated Carbon Component Manager for hosting Audio Units. Support
for this will be removed in a future release. Also, this makes the
host incompatible with version 3 audio units. Please transition to the
API's in AudioComponent.h.
Here's the entire code.
It's a sudoku game that should display a board with Sudoku being solved.
(This answer is not directed to the original question but to anyone who might have the same problem)
In the game loop you have to process/check events so that pygame knows your game hasn't crashed:
screen = pygame.display.set_mode((1000, 500))
while True:
for event in pygame.event.get():
# process events
# Update your sprites
pygame.display.update()

pygame will not load my game when i run it?

I am currently making a basic 2D platform game and all I have made so far is the background for the start menu. But when I run it does not run my game. Once in a while it will run it and everything will show up but there is a black block covering part of the window?
Can someone explain why this is?
bif=("cloud.jpg")
import pygame,sys
from pygame.locals import *
pygame.init()
screen=pygame.display.set_mode((813,555),0,32)
pygame.display.set_caption('Red Dwarf')
background=pygame.image.load(bif).convert()
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
screen.blit(background,(0,0))
pygame.display.update()
As I answered in your other question already: Indendation...!
Your pygame.display.update() is outside the while loop. This means that it is not called until the while loop has finished and that's not going to happen here, therefore the display is just never ever updated.
Indend the pygame.display.update() to the level of screen.blit(background,(0,0)) and it will work just fine.

Categories