Is there a way to write a function that returns a global variable (creating the variable inside the function and returning it outside, globally)? I can't assign the variable before the function call because I'm using it on tkinter, therefore, it's on a While loop.
No, a function can set a global variable but cannot return any local variable/ value that can impact a global state.
Generally, global variables are bad and make it really hard to reason about your program. Try your best to use pure functions with only local state
A function that returns a global variable