I'm having a problem to load the checkbox state from a text file that contain '0' and '1'.
inside "test.txt" file :
1
0
1
0
This is what I'm expecting the outcome to be as '1' represent checked box and '0' represent unchecked box
Below is the code I'm working on :
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry("180x90")
name1 = ["Mike", "Harry", "Siti", "Jenn"]
def loadstates():
f = open("test.txt", "r")
list_a = []
list_a = f.readlines()
return list_a
f.close()
def createCheckboxes():
for x, y in zip(st, name1):
check = ttk.Checkbutton(root, text=y, variable=x)
if x=='0':
check.select()
else:
check.deselect()
check.pack(anchor=tk.W)
st = loadstates()
createCheckboxes()
root.mainloop()
But it gives out error :
Traceback (most recent call last): File "C:/Users/jmamuham/PycharmProjects/LogBook/load_state.py", line 24, in createCheckboxes() File "C:/Users/jmamuham/PycharmProjects/LogBook/load_state.py", line 20, in createCheckboxes check.deselect() AttributeError: 'Checkbutton' object has no attribute 'deselect'
Any idea why .select() and .deselect() gives me this error?
By the way, am I using the correct approach to repopulate the checkbox state using 1 and 0?