How to get checkbox values to save into a text file?
Your var_states
function doesn't actually return anything. It just prints to the console. Change it to:
def var_states(): res = "Option 1: %d\nOption 2: %d" % (var1.get(), var2.get()) print(res) return res
Also, instead of manually open
ing and close
ing files, you should use with
:
with open("output.txt", "w") as f: f.write(var_states())#open and read the file after the appending:with open("output.txt", "r") as f: print(f.read())
The file is automatically close
d at the end of the with
block.