How to get checkbox values to save into a text file? How to get checkbox values to save into a text file? tkinter tkinter

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 opening and closeing 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 closed at the end of the with block.