Python Forum
How to get screen to clear?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get screen to clear?
#2
You have to set a flag and fill the screen every frame. Currently you are only filling the screen on the frame that a mouse button is down and the mouse is in collision with your student rect.

Here is an example that when you press a mouse button it switches to and from white.
import pygame as pg

pg.init()
screen = pg.display.set_mode((800,600))
running = True
bg_white = False


while running:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            running = False
        elif event.type == pg.MOUSEBUTTONDOWN:
            bg_white = not bg_white
            
    if bg_white:
        screen.fill((255,255,255))
    else:
        screen.fill((0,0,0))
    pg.display.update()
Recommended Tutorials:
Reply


Messages In This Thread
How to get screen to clear? - by mzmingle - Oct-09-2018, 11:17 AM
RE: How to get screen to clear? - by metulburr - Oct-09-2018, 05:05 PM
RE: How to get screen to clear? - by mzmingle - Oct-10-2018, 08:22 AM
RE: How to get screen to clear? - by metulburr - Oct-10-2018, 11:40 AM
RE: How to get screen to clear? - by mzmingle - Oct-10-2018, 11:41 AM
RE: How to get screen to clear? - by metulburr - Oct-10-2018, 12:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] When I hit the space bar from the home screen, it sends me to the game over screen JesusisKing 1 1,037 Apr-30-2023, 10:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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