Why is there a white line in my pygame window?

Viewed 55

I have tried looking for answers on this site, but I couldn't find one. If I change the size of my window, using the change_size() function, there is a white line. Anyone know how to solve this?

import pygame
pygame.init()
class Window:
   def __init__(self,title='Window', height=500,width=500):
        pygame.display.set_caption(title)
        screen = pygame.display.set_mode((height,width))
   def change_caption(self, caption):
        pygame.display.set_caption(caption)
   def change_size(self,height=500, width=500):
        screen = pygame.display.set_mode((height,width))
1 Answers

Most probably because you did not update the display with pygame.display.update().

Try this short code that changes size after about 3 seconds.

import pygame
import time
import sys


pygame.init()


class Window:

    def __init__(self,title='Window', height=500,width=500):
        pygame.display.set_caption(title)
        self.screen = pygame.display.set_mode((height,width))

    def change_caption(self, caption):
        pygame.display.set_caption(caption)

    def change_size(self,height=500, width=500):
        self.screen = pygame.display.set_mode((height,width))


if __name__ == "__main__":
    win = Window()
    start = time.time()

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

        if time.time() - start > 3:
            win.change_size(600, 600)

        pygame.display.update()
Related