Skip to content
Advertisement

Skip None values in entry widgets Tkinter Python

Let’s say we have a Tkinter app with many entry widgets like this:

JavaScript

The values from these widgets are used to UPDATE a database. The thing I want is to be able to skip a value in anyone of them and not use it in the UPDATE statement. For now with my code I check if there is something written in the widgets like this:

JavaScript

The problem is that when one of the values is None in the database I get a value of NULL which is correct, because there is no value in the widget. How can I ‘tell’ python that when there is no value presented it should skip that value and continue to update just the others?

EDIT: Thanks to @TheLizzard this solution works like a charm:

JavaScript

EDIT2: After a bit of research, and thanks to @TheLizzard, @Arioch ‘The, @Mark Rotteveel I’ve come with the following working code and following one of the suggestions here this is safe now:

JavaScript

And the result is:

JavaScript

Advertisement

Answer

Try this:

JavaScript

I dynamically create a string starting with "UPDATE table1 SET " and ending in ";" where I skip all of the values that are "".

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement