To do thins this way you would need to put global value as the very first line in the callback function. In Python you can read from values outside a function, but assignments to variables inside functions are assumed to be local to the function, unless explicitly made global.