Bug with python mode

Try using the ‘global’ keyword inside the draw function.
This keyword is to be used if you want to assign the value of an initialized global variable inside a function.

txt = '1';

def setup():
    size(600,600)
    noFill()
    noStroke()

def draw():
    global txt
    fill('#FF0000') # red quadrant
    rect(width/2,0, width/2,height/2)

    fill('#004477') # blue quadrant
    rect(0,0, width/2,height/2)

    fill('#6633FF') # violet quadrant
    rect(0,height/2, width/2,height/2)

    fill('#FF9900') # orange quadrant
    rect(width/2,height/2, width/2,height/2)
    
    fill(255)
    if mouseX < width/2 and mouseY < height/2:
        #text("BLUE",mouseX,mouseY)
        txt = 'BLUE'
    if mouseX < width/2 and mouseY > height/2:
        #text("PURPLE",mouseX,mouseY)
        txt = 'PURPLE'
    if mouseX > width/2 and mouseY < height/2:
        #text("RED",mouseX,mouseY)
        txt = 'RED'
    if mouseX > width/2 and mouseY > height/2:
        #text("YELLOW",mouseX,mouseY)
        txt = 'YELLOW'
    text(txt,mouseX,mouseY)
3 Likes