class MainWindow(Tk):
styler = ttk.Style()
storage = ...
current_left = ...
....
...
def __init__(self):
super().__init__()
self.title("PyCalc")
...
styler.theme_use("calm")
...
and next you can use storage or temporary operand variables in any method here or directly pass it in other objects, for ex.:
def put_in_storage(): # cout
storage[-1] = ...
...
This step needs to separate the gui functionality and the core program logic so you can independently change them.
class Controls:
operators = [....]
special = [...]
...
and make an instance of this class a field of your MainWindow class. Using this approach you can easily bind control elements like:
def control_binding():
for control_element in [str(x) for x in range(10)]: # or your controls list
some_button= ttk.Button(keypad, text=control_element, command=lambda: cout(control_element))
# or append this buttons to button list and like button_list.append(some_button)
nine = ttk.Button(keypad, text='9', command=lambda: cout('9'))
eight = ttk.Button(keypad, text='8', command=lambda: cout('8'))
seven = ttk.Button(keypad, text='7', command=lambda: cout('7'))
six = ttk.Button(keypad, text='6', command=lambda: cout('6'))
five = ttk.Button(keypad, text='5', command=lambda: cout('5'))
four = ttk.Button(keypad, text='4', command=lambda: cout('4'))
three = ttk.Button(keypad, text='3', command=lambda: cout('3'))
two = ttk.Button(keypad, text='2', command=lambda: cout('2'))
one = ttk.Button(keypad, text='1', command=lambda: cout('1'))
zero = ttk.Button(keypad, text='0', command=lambda: cout('0'))
I think you would got a point.
if cond1:
if cond2:
if cond3:
...
else:
..elses..
if not cond1:
...
return
if not cond2:
...
return
I think you would got a point.
I recommend you to read "Clean code" by Robert Martin. There are a lot of guidelines to improve your code quality with perfect argumentation.