Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a Checkbutton/box change a text file on-click? (Using Python and tkinter library)
    text
    copied!<p>So, I decided to make this project of building a program so I could have a record of my books, which of them I borrowed, which I've read, etc. For the "database" I'm using .txt files, which contain the book titles, authors, etc. One at a line and all a book shares the same line with it's author, but they are in separate files. So, for example, I've got:</p> <pre><code>FILE A: | FILE B: Harry Potter | J.K. Rowling The Fellowship of the Ring | J.R.R. Tolkien </code></pre> <p>And so on with all the other Info.<br> Now, I've added a checkbutton for each book, so that I can mark the ones I've read, and created a .txt file called read with "SELECTED" or "NOT-SELECTED" in each line to represent the state of the Checkbutton.<br> I, then add the checkbuttons to the program through a for loop that runs through the read.txt file and adds as many check buttons as there are lines in the file. If the line in the file reads "SELECTED", then it sets the checkbutton as selected (<code>checkbutton.selected()</code>), else it just creates the checkbutton.<br> Now, what I want is that the program will change the line in the read.txt file as soon as the corresponding-line button is pressed, so, if I press the button for Harry Potter, for example, the first line in read.txt will be changed to "SELECTED", and if I click it again it will be changed back to "NOT-SELECTED".<br> What I first thought about doing was to create a list with the values of each check button, and then when any check button gets pressed, it will call a function that creates a new list, with the new values of each button. It would, then, compare the two lists and make the necessary changes to the first, then changing the file. The problem is, I have no idea of how to create the secont list, to compare, so I'm looking for help on how to do it. If someone has a better idea, though, it would be more than welcome.</p> <p>Sorry for the long post.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload