dimanche 25 octobre 2020

How to change a list depending on tkinter checkbutton

I have been trying to use tkinter CheckButton widget to edit items in a list - each item of the list is a new checkbutton. I want a save method to save the data to a text file, and a load method to load the info from the text file and mark the checkbutton boxes depending on the items in the list.

Here is my code so far, but the list doesn't seem to change when I check the buttons and update the list/file

Here is my code, I need to know why the list isn't updating when I check the boxes:

import tkinter.messagebox as box

modulesMain = Tk()
modulesMain.title("Edit OinK Modules")

moduleChecks = []

def SaveChanges():
    # Clear the text file
    modules = open("modules.txt", "w") #Write mode to overwrite the whole file
    modules.write("") # Put in blank text
    modules.close()

    modules = open("modules.txt", "a") # Append mode to append the file
    for item in moduleChecks:
        modules.write(item + "\n")
    print(moduleChecks)


def ReadModules():
    modules = open("modules.txt", "r")
    for line in modules:
        moduleChecks.append(line.strip())
    print(moduleChecks)

ReadModules()


appButton = Checkbutton(modulesMain, text = "Test", variable = moduleChecks[0]).grid()
searchButton = Checkbutton(modulesMain, text = "Test", variable = moduleChecks[1]).grid()






Save = Button(modulesMain, text = "Save Changes", command = SaveChanges).grid()



Aucun commentaire:

Enregistrer un commentaire