I am trying to load checkbox values from a text file.
Let me explain..
Here is the screen:
I have a piece of code that saves the results into a .txt file.
Here is the .txt file:
Now, when I close & re-open the .py file, everything resets.
I'd like to implement a button that will load last row from txt file and do the following:
If option1
is 0
and option2
is 1
from text file, when clicked load, the option2
check box will be the only one checked.
Like this:
Intended result when loading the txt file
How can this be achieved?
Here is my current code:
from tkinter import *
master = Tk()
master.minsize(200, 100)
var = IntVar()
var2 = IntVar()
a = Checkbutton(master, text="Option 1", variable=var)
a.pack()
b = Checkbutton(master, text="Option 2", variable=var2)
b.pack()
def save():
text_file = open("text.txt", "a")
text_file.write("Option1 %d Option2 %d \n" % (var.get(), var2.get()))
text_file.close()
Button(master, text = "Save", command = save ).pack()
mainloop()