Jump to content
  • Advertisement
Sign in to follow this  

[Python] Redraw blank screen help

This topic is 3314 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to get n to redraw a blank white screen but it will not work.
import pygame

def main():
	screen = pygame.display.set_mode((640,480))
	pygame.display.set_caption("Draw Lines Program")
	bg = pygame.Surface(screen.get_size())
	clock = pygame.time.Clock()
	run = True
	while run:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				run = False
			elif event.type == pygame.MOUSEBUTTONDOWN:
				MouseD = pygame.mouse.get_pos()
			elif event.type == pygame.MOUSEBUTTONUP:
				MouseU = pygame.mouse.get_pos()
				pygame.draw.line(bg, (0,0,0), MouseD, MouseU, 3)
			elif event.type == pygame.KEYDOWN:
				if event.key == pygame.K_f:
					pygame.image.save(bg, "pic1.bmp")
				elif event.key == pygame.K_n:
					screen.blit(bg, (0,0))
		screen.blit(bg, (0,0))
if __name__ == "__main__":

Share this post

Link to post
Share on other sites
The code you are using to "draw a blank white screen" for the N key is the same as the code you use unconditionally each time through the loop to refresh the current screen state: screen.blit(bg, (0,0)). It should be no surprise that the N key therefore fails to do anything visible. It also shouldn't have been hard to pick up on this, seeing as those two lines of source code come one right after the other (whitespace and indentation notwithstanding).

Since 'bg' will be blitted to screen regardless, what the N key should do is cause 'bg' to become a blank white screen. The way to do this is the same way that you do it before the loop starts: bg.fill((255,255,255)).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!