Python Forum

Full Version: how to make a rectangle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
im trying to make a rectangle on my screen and the rectangle shows up but for a split second after i click the close button this is my code in the main.py:
import pygame
from settings import *
from tiles import *

background_colour = (0, 0, 0)

screen_width = 800
screen_height = 600

screen = pygame.display.set_mode((screen_width, screen_height))
test_tile = pygame.sprite.Group(Tile((100, 100), 200))

pygame.display.set_caption("my screen")


screen.fill(background_colour)


pygame.display.flip()


running = True


while running:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False


pygame.display.update()

clock.tick(60)
and this is my code in the tilels.py:
import pygame

class Tile(pygame.sprite.Sprite):
	def __init__(self,pos,size):
	    super().__init__()
	    self.image = pygame.Surface((size,size))
	    self.image.fill('grey')
	    self.rect = self.image.get_rect(topleft = pos)
so i dont know how to make it show up while it is running please help.[attachment=1673][attachment=1674]