This question already has answers here:
How do I maximize the display screen in PyGame?
(6 answers)
Closed 6 days ago.
How do I "maximize" a window in pygame, with "maximize" I mean this:
Not this:
Do you have any idea of how can this be done?
You can maximize the Pygame window using the set_mode() method and passing the pygame.FULLSCREEN argument:
import pygame
pygame.init()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
# your code here
pygame.quit()
This will make the window display in full screen. If you want to exit full screen mode, just press the "Esc" key or call the set_mode() method again, this time without the pygame.FULLSCREEN argument.
Related
This question already has answers here:
How to draw a chessboard with Pygame and move the pieces on the board?
(1 answer)
Drag multiple sprites with different "update ()" methods from the same Sprite class in Pygame
(2 answers)
How can I drag more than 2 images in PyGame?
(1 answer)
How do I add a rubber band for mouse dragging in PyGame? [closed]
(1 answer)
Closed 23 days ago.
I want to be able to click on the box and then click somewhere else and have it move to that location. I have no idea how to do it. Some of the ways I tried work but they only work for one image(if i have 2 or more boxes it wont work). Can you modify this code so when the box is clicked it becomes selected, then if anywhere else on the screen is clicked, the box will move to that new location?
Here is the code:
import pygame # Import the pygame module
# Initialize pygame
pygame.init()
# Set the screen size
screen = pygame.display.set_mode((512, 512))
# Set the title of the screen
pygame.display.set_caption("Screen")
image = pygame.transform.scale(pygame.image.load('image.png'),(64,64))
# Run the game loop
running = True
while running: # Main game loop
for event in pygame.event.get(): # Check for events
if event.type == pygame.QUIT: # If the user clicks the close button
running = False # Exit the game loop
# Clear the screen
screen.fill((255, 255, 255))
# Draw the image#
screen.blit(image,(224,224))
# Update the screen
pygame.display.update()
# Quit pygame
pygame.quit()
This question already has answers here:
Why is nothing drawn in PyGame at all?
(2 answers)
Closed 7 months ago.
I was trying to create a small ping-pong game with python and pygame, but I run into a huge problem: it doesnt work.
My code opens a window, but doesn't fill it. I've tried different variants of solving, but nothing seems to help. And I tried to compile this code in online compiler (Replit), but it doesn'tseem to work there neither.
import pygame
#screen initializing
WIDTH, HEIGHT = 900, 500
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Ping-Pong')
for i in range(1000):
screen.fill((200, 200, 200))
this code just opens a black window, no matter what number I write in. What can cause fill() function to not work?
Add pygame.display.update() at the end to update the screen
This question already has answers here:
Multiple Displays in Pygame
(3 answers)
Pygame with Multiple Windows
(4 answers)
PyGame os.environ SDL_VIDEO_WINDOW_POS does not work
(2 answers)
Closed 1 year ago.
I'm implementing a code that shows up an image in fullscreen size, using PyGame. I have two screens in my setup, one monitor and the one of the laptop. When I run my code to show on the monitor all works fine, but when I try it on the laptop screen something crash, and only a black screen is shown. My code is as follows:
def open_window2(path, key):
# key dict
key_dict={'a':K_a, 'b':K_b, 'c':K_c, 'd':K_d, 'e':K_e, 'f':K_f,
'g':K_g, 'h':K_h, 'i':K_i, 'j':K_j, 'k':K_k, 'l':K_l,
'm':K_m, 'n':K_n, 'o':K_o, 'p':K_p, 'q':K_q, 'r':K_r,
's':K_s, 't':K_t, 'u':K_u, 'v':K_v, 'w':K_w, 'x':K_x,
'y':K_y, 'z':K_z}
pygame.init()
# get screen resolution
resolution = (pygame.display.Info().current_w, pygame.display.Info().current_h)
surface = pygame.display.set_mode(resolution, FULLSCREEN)
image = pygame.image.load(path)
image = pygame.transform.scale(image, resolution)
rect = image.get_rect(); rect.center = resolution[0]//2, resolution[1]//2
surface.blit(image, rect)
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN: #press-key events
if event.key == key_dict[key]: # if C key is pressed ...
running = False
pygame.quit()
When I set it to pygame.FULLSCREEN shows a black screen, but when I set it to pygame.RESIZABLE the image is shown.
What should I do to fix the black screen problem?
I've found a solution. I don't know how pyglet.FULLSCREEN flag works but there is another way to do that without using it. You can just join two flags, pyglet.SCALED and pyglet.NOFRAME and it should work well.
surface = pygame.display.set_mode(resolution, pygame.SCALED|pygame.NOFRAME).
pygame.SCALED refers to adjust to the fullscreen mode, and pygame.NOFRAME removes bars and other showing parts.
It will plot the image you want on the entire screen, without showing bars, menus, etc.
This question already has answers here:
The fullscreen mode in pygame is entirely black
(1 answer)
Switching to Pygame Fullscreen Mode working only one time
(1 answer)
Closed 2 years ago.
I am developing a game and I went into a problem which I could not solve. I want to have a pygame screen which adjusts in every screen, because you can see more of the game background when you have a very large screen and when you have a small screen, you will only see a small piece of the game. I dont know how to fix this. (If it is possible, it would be nice when I can scale every object together)
Code:
pygame.init()
os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0"
display_info = pygame.display.Info()
MONITOR_SIZE = width, height = pyautogui.size()
pygame.display.set_caption("Stickman fight")
screen = pygame.display.set_mode(MONITOR_SIZE, pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN, 32)
bgs = [pygame.transform.scale2x(pygame.image.load("src/Img/Bg1.jpg").convert_alpha())]
This question already has answers here:
How to wait some time in pygame?
(3 answers)
Why doesn't PyGame draw in the window before the delay or sleep?
(1 answer)
How do you make Pygame stop for a few seconds?
(1 answer)
Closed 2 years ago.
I have some simple code here that is not behaving as I expected:
import pygame,sys
from pygame.locals import *
pygame.init()
window = pygame.display.set_mode((1300,700))
while True:
window.fill((0,0,0))
pygame.display.update()
#show black window, should happen before wait
pygame.time.wait(2000)
#program waits for 2 seconds, and then shows black window
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit(0)
The program waits for 2 seconds before updating the display and showing the black window. Why? Since python is an interpreted language, shouldnt pygame.display.update() happen before pygame.time.wait(2000)?