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.
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:
Could not open resource file, pygame error: "FileNotFoundError: No such file or directory."
(1 answer)
Is there any other way to load a resource like an image, sound, or font into Pygame? [closed]
(1 answer)
Closed 2 years ago.
I recently started to learn to use the pygame module and I've run into my first blocker. I an trying to paste an image of a circle in a grid that I created on top of my solid background. For some reason when I blit the image and update the screen nothing appears and I am not sure why as I am pretty sure that my code is correct. I've pasted my code below. Maybe you guys will see what I am missing.
from pygame import *
def main():
init()
display.set_caption("Othello")
screen = display.set_mode((480,480))
screen.fill((0,128,0))
draw.line(screen,(0,0,0),(60,0),(60,480))
draw.line(screen,(0,0,0),(120,0),(120,480))
draw.line(screen,(0,0,0),(180,0),(180,480))
draw.line(screen,(0,0,0),(240,0),(240,480))
draw.line(screen,(0,0,0),(300,0),(300,480))
draw.line(screen,(0,0,0),(360,0),(360,480))
draw.line(screen,(0,0,0),(420,0),(420,480))
draw.line(screen,(0,0,0),(0,60),(480,60))
draw.line(screen,(0,0,0),(0,120),(480,120))
draw.line(screen,(0,0,0),(0,180),(480,180))
draw.line(screen,(0,0,0),(0,240),(480,240))
draw.line(screen,(0,0,0),(0,300),(480,300))
draw.line(screen,(0,0,0),(0,360),(480,360))
draw.line(screen,(0,0,0),(0,420),(480,420))
display.flip()
image_white = image.load("White_Side.jpg")
image_black = image.load("Black_Side.jif")
screen.blit(image_white,(0,0))
screen.blit(image_black,(60,0))
display.update()
running = True
while running:
for pygame_event in event.get():
if pygame_event.type == QUIT:
running = False
if __name__=="__main__":
main()