Reputation: 493
I have a program with a pygame resizable window.
screen = pygame.display.set_mode(size,pygame.RESIZABLE)
Since it is resizable, I want certain elements on the screen to change position and size in accordance to the window size.
I have all of my variables saved in the function setGet. I want the pass in the screen size and have all of the variables be dependent on that screen size passed in.
def setGet(screenSize):
I have a looping function that runs the command
setGet(screen.get_size())
The get_size() apperently doesn't get updated when you change the size of the window.
How can I update the size of the screen when resizing the window?
Upvotes: 1
Views: 4561
Reputation: 41
changed = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit(0)
elif event.type == pygame.VIDEORESIZE:
scrsize = event.size
width = event.w
hight = event.h
screen = pygame.display.set_mode(scrsize,RESIZABLE)
changed = True
it's almost exactly like this in the comments for pygame.display.init doc page https://www.pygame.org/docs/ref/display.html#comment_pygame_display_update edited only slightly from 2011-01-25T23:10:35 - Dave Burton thanks dave
Upvotes: 2
Reputation: 493
Well I guess I found my own answer.
what you want to do is have resizing the window be an event.
so what you want is
if event.type == pygame.VIDEORESIZE:
setGet(event.size)
Upvotes: 4