I'm using appJar to create a GUI and I'm trying to check if a button was clicked or not, so I thought of creating a flag to do that, however it does not work as I expected. I want the program to do the following:
Scenario 1:
1- Load dictionary
2- 'Replace' button clicked > dictionary is not updated
Scenario 2:
1- Load dictionary
2- 'Update dictionary' button is clicked > set flag to 'yes'
3- 'Replace' button clicked > reload dictionary
My code:
# defined flag globally
global flag
flag = 'no'
# Function to change the global var -flag-
def anyUpdate(f):
if f == 'yes':
flag = f # change global variable -flag- to 'yes'
return True
else:
return False
def press(btn):
# Edit dictionary clicked
if btn=="Update dictionary":
anyUpdate('yes') # call function - 'yes' sent
# Replace clicked
if btn=="Replace":
if someNotImportantCode:
someCode
else:
print flag # prints 'no' even if update dictionary clicked means global var didn't change
checkUpdate = anyUpdate(flag) # call function - global var sent
print checkUpdate # prints False of course since flag is 'no'
if checkUpdate == True:
# reload dictionary
reps = getDictionary()
As you see the global flag doesn't change. I feel my idea isn't very good, but I've tried different codes nothing is working for me and I feel stuck. Any help?