You need to understand that this type of post really IS spam of the forums. Your troubles have a lot to do with the fact that you are learning how to program in Python. These types of posts pollute the forum with code that is not useful for solving Pythonista problems and degrades the ability for other users to search for answers to problems in the future. It is akin to grafitti since other users in the future may stumble across this stuff and use it.
You have already benefitted greatly by getting advice from users like JonB to "refactor" your code and eliminate the globals. If you would just listen to that advice and do that, you will likely figure out what is wrong with your program along the way.
The key thing is that this has nothing to do with Pythonista!!!! Take it to stackoverflow or some other forum that is geared toward answering questions about programming in Python. PLEASE!
I am going to mark this posting for moderation but don't take it personally. I can see that your are just trying to learn and I really appreciate that.