Skip to Content
Python GUI Programming with Tkinter
book

Python GUI Programming with Tkinter

by Alan D. Moore
May 2018
Beginner to intermediate content levelBeginner to intermediate
452 pages
11h 26m
English
Packt Publishing
Content preview from Python GUI Programming with Tkinter

Adding update to save_record()

To convert our save_record() method so that we can update records, the first thing we'll need to do is provide the ability to pass in a row number to update. The default will be None, which will indicate that the data is a new row that should be appended.

The new method signature looks like this:

    def save_record(self, data, rownum=None):
        """Save a dict of data to the CSV file"""

Our existing logic doesn't need to change, but it should only be run if rownum is None.

So, the first thing to do in the method is check rownum:

        if rownum is not None:
            # This is an update, new code here
        else:
            # Old code goes here, indented one more level

For relatively small files, the simplest way to update a single row is to load ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python GUI Programming with Tkinter - Second Edition

Python GUI Programming with Tkinter - Second Edition

Alan D. Moore

Publisher Resources

ISBN: 9781788835886Supplemental Content