Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to make a rectangle
#1
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.
.py   main.py (Size: 570 bytes / Downloads: 147)
.py   tiles.py (Size: 236 bytes / Downloads: 153)
Larz60+ write Mar-25-2022, 03:21 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Please use BBCode on future posts.
I also took the liberty, and reformatted the first script to make it more readable.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020