I am trying to make a draw program in pygame for a school project. In this module, i am intending for the user to press down on the mouse and draw a line on the surface. If a person presses down on a rect, the color that the person selected is the color that the drawn line will be. For some reason, the variable can change but even if i press down the mouse, no line is drawn. Here's the code:
def painting_module():
running = True
while running:
#clock for timingn processes
Clock.tick(FPS)
# Process input (event)
for event in pygame.event.get():
Mouse_location = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
displacement_val = pygame.mouse.get_rel()
color_to_paint_with = (0,0,0)
if event.type == pygame.QUIT:
running = False
if click[0] == 1:
# Intended to select colors if pressed, draw a line if the mouse is not on the rect
if red_rect.collidepoint(Mouse_location):
color_to_paint_with = RED
print "Red"
print color_to_paint_with
if green_rect.collidepoint(Mouse_location):
color_to_paint_with = GREEN
print "red"
print color_to_paint_with
if blue_rect.collidepoint(Mouse_location):
color_to_paint_with = BLUE
print "red"
print color_to_paint_with
if gray_rect.collidepoint(Mouse_location):
color_to_paint_with = GRAY
print "red"
print color_to_paint_with
if eraser_ivory_rect.collidepoint(Mouse_location):
color_to_paint_with = IVORY
print "red"
print color_to_paint_with
#draws the line
pygame.draw.line(Screen, color_to_paint_with, Mouse_location, (Mouse_location[0] + displacement_val[0], Mouse_location[1] + displacement_val[1]))