Don't use globals ... If you want to modify an object python has mutable objects. These are structures that are passed by reference and the function will change the value inside the structure everywhere.
Below is a basic example of pass by value where the value outside the scope of the function does not change. Below the variable "c" is an immutable object, the value of c will not be changed from a function. Immutable vs Mutable types
c = 0
def foo(c):
c = c + 1
return c
m = foo(c)
print(c) # 0
print(m) # 1
Here is an example of a mutable object and pass by reference (I believe python always does pass by reference but has mutable and immutable objects).
c = [0]
def foo(c):
c[0] = c[0] + 1
return c
m = foo(c)
print(c) # [1]
print(m) # [1]
or make a class. Anything but globals.
class MyCount(object):
def __init__(self):
self.x = 0
# end Constructor
def B_C(self):
self.x += 1
pass # do stuff
# end B_C
def __str__(self):
return str(self.x)
# end str
# end class MyCount
c = MyCount()
c.B_C()
print(c)
c.B_C()
print(c)
Also you mentioned that you were using a button. If you want a button press to pass an argument into the function you may have to use a lambda function. I don't really know about TKinter, but for PySide you have connect the button to call a function on click. There may not be an easy way to pass a variable into the button click function. http://www.tutorialspoint.com/python/tk_button.htm
def helloCallBack(txt):
tkMessageBox.showinfo("Hello Python", txt)
# from the link above
B = Tkinter.Button(top, text="Hello", command= lambda x="Hello": helloCallBack(x))
# lambda is actually a function definition.
# The lambda is like helloCallBack without the parentheses.
# This helps you pass a variable into a function without much code