Great question @CodeMasterX, and the answers by @SierraMike and @GoToLoop will help you solve this issue 
Just to give you a bit more context of what is going on… in your code without modifications your local txt variable fails to be assigned in some edge case (I would guess it is when the mouse is exactly in the middle of the screen and no if clauses are True).
One solution would be at the start of draw() to assign txt = '1' (then you don’t need the global assignment, please remove it from the start of your sketch for clarity!) otherwise you should be using the global statement for the global variable strategy as the other answers have indicated.