Reputation: 31
To resize the display, I would write code like this:
pygame.display.set_mode((1000, 500), pygame.RESIZABLE)
But I don't like the display frame, so I decided to reject it:
pygame.display.set_mode((1000, 500), pygame.NOFRAME, pygame.RESIZABLE)
And the problem is start here, I wanna resize the display automatically as pressing a key, or clicking a button inside the pygame window, but I cannot resize my pygame display, automatically.
I did try some code like this(parts of codes):
resize_y = 0 # Don't resize when the program start
console = pygame.display.set_mode((370, 500+resize_y), pygame.NOFRAME, pygame.RESIZABLE) # Expands by resize_y
def main():
main = True
while main:
for event in pygame.event.get(): #skip quit code
if event.type == pygame.KEYDOWN and event.key == pygame.K_d:
resize_y += 100 #Add resize_y
console.fill((255, 255, 255)) # Fill background with white
pygame.display.update()
main() # call main
There was no Error message, didn't work, and of course I expected extenting display when I press D.
How can I fix?
Upvotes: 1
Views: 355
Reputation: 101042
First of all, all flags have to be passed to set_mode
with the single the flags
argument. In your code, you pass RESIZABLE
as the depth
argument. Use or
to set multiple flags.
Second, you write:
To resize the display, I would write code like this: pygame.display.set_mode((1000, 500), pygame.RESIZABLE)
but you don't actually call pygame.display.set_mode
after changing resize_y
.
You're code should look more like this:
import pygame
def main():
resize_y = 0 # Don't resize when the program start
console = pygame.display.set_mode((370, 500+resize_y), pygame.NOFRAME or pygame.RESIZEABLE) # Expands by resize_y
running = True
while running:
for event in pygame.event.get(): #skip quit code
if event.type == pygame.QUIT:
return
if event.type == pygame.KEYDOWN and event.key == pygame.K_d:
resize_y += 100 #Add resize_y
console = pygame.display.set_mode((370, 500+resize_y), pygame.NOFRAME or pygame.RESIZEABLE)
console.fill((255, 255, 255)) # Fill background with white
pygame.display.update()
main() # call main
But note that the RESIZABLE
flag is basically useless in combination with the NOFRAME
flag. If you want to change the size of the window within your code, you don't need RESIZABLE
and can savely remove it. Use it only when the user should be able to resize the window.
Upvotes: 1