I am trying to make a simple calculator with Python Tkinter. Below you can see a piece of code and a variable "sign" in it. I want the variable to serve as a way to tell the program that addition button of my calculator was pressed.
def addition():
sign = "+"
first_number = e.get()
global first_converted
first_converted = int(first_number)
e.delete(0, END)
Further in the code, I want to make a function that will contain "if" statements for all of the scenarios of pressed buttons e.g. addition, division, multiplication, etc. However, Python does not see variable "sign".
def count():
if sign == "+":
pass
e.delete(0, END)
pass
I have tried declaring variable as global in the beginning of the code, but it did not help.
signinadditionis not the same as thesignincount. You should pass the values referred to by variables as arguments to other functions that need them. While you can also "pass" values asglobal, this is problematic when values need to be modified.signhas to be declared global in any function that assigns to it.