How to avoid global variables and static methods using __init__ method? How to avoid global variables and static methods using __init__ method? tkinter tkinter

How to avoid global variables and static methods using __init__ method?


You need to learn about variable scope. You define output inside the __init__ method, so it is local to that method only; once that finishes, the variable is destroyed, and it isn't available from anywhere else.

But __init__ and the other methods are all part of the same class; one of the whole points of classes is that you can set instance variables. In this case, you want to assign to self.output, and reference that inside nextnum and reset.

Really, you should do the same with i and k, then you don't need any global declarations at all.