You can't call a function before it's defined.
But simply moving the definition before the call could solve that particular problem.
Having said that, what you're doing is really weird, for a few reasons:
- you don't need to use regex to do simple substitutions like this. str.replace() should be powerful enough
- opening a file in 'rb+' mode is rarely a good thing to do. It is better to open the original file for reading, and the new one for writing
- everything you want to happen when the button is clicked should be inside of the new_proj() function(so don't return x, create the new file inside the function)
- that jojo() call makes no sense