Jul-31-2019, 01:52 PM
Hi!
This i s my first post, i got a problem with code what i make. Problem is that pickle dont get ver. when is changed in tkinter. I use many steps to check when ver. is 0 or 1. Maybe something wrong with declaration of var?
here is repls: https://repl.it/repls/CadetblueMysteriousTechnician
This i s my first post, i got a problem with code what i make. Problem is that pickle dont get ver. when is changed in tkinter. I use many steps to check when ver. is 0 or 1. Maybe something wrong with declaration of var?
here is repls: https://repl.it/repls/CadetblueMysteriousTechnician
import tkinter as tk import pickle s1=s2=s3=0 class Cbuttons: def __init__(self): self.root = tk.Tk() self.root.title("Checklist") self.CheckVar1 = tk.IntVar() self.CheckVar2 = tk.IntVar() self.CheckVar3 = tk.IntVar() self.main() def save(self): print('To save:',s1,s2,s3) with open('asy.txt', 'wb') as f: pickle.dump([s1,s2,s3], f) print('Saved!',s1,s2,s3) def loading(self): with open('asy.txt', 'rb') as f: s1,s2,s3= pickle.load(f) print(s1,s2,s3) def confirm(self): if self.CheckVar1.get(): s1=1 pickle.dump(s1, open("asy.txt", "wb")) else: s1=0 if self.CheckVar2.get(): s2=1 else: s2=0 if self.CheckVar3.get(): s3=1 else: s3=0 print('chek status:',s1,s2,s3) self.save() def main(self): C1 = tk.Checkbutton(self.root, text="Option A", variable=self.CheckVar1, anchor='w', onvalue=1, offvalue=0, height=1, width=40, command=self.confirm) C2 = tk.Checkbutton(self.root, text="Option B", variable=self.CheckVar2, anchor='w', onvalue=1, offvalue=0, height=1, width=40, command=self.confirm) C3 = tk.Checkbutton(self.root, text="Option C", variable=self.CheckVar3, anchor='w', onvalue=1, offvalue=0, height=1, width=40, command=self.confirm) C1.pack() C2.pack() C3.pack() b = tk.Button(self.root, text="OK", command=self.loading) b.pack() self.root.mainloop() if __name__ == '__main__': Cbuttons() #https://python-forum.io/Thread-Tkinter-Print-if-all-checkboxes-marked