Skip to content
Advertisement

Any way to censor Treeview Data Display?

I am able to use SQLite3 as the database (DB) and get Treeview to display data from the DB. However, I was wondering whether Treeview has any functionality to censor the first few characters in a certain column for all entries?

Here is the lean code:

JavaScript

I can get variables from the Entry Widget (with Tkinter) to be successfully stored and reflected from the updated DB to the Treeview upon the view_database() function call. But I was hoping to censor the first 5 characters of nric column data with * for all entries when viewing the Treeview. Would that be possible or an alternative method to work around with?

Advertisement

Answer

You can make the substitution in the SQL query itself, by combining your desired prefix with a substring of the column, taken from the sixth character to the end.

Here’s a pure Sqlite example:

JavaScript

substr is a function that takes a substring of a string value, || is the string concatenation operator.

Labelling the new value with AS redacted will have Sqlite returned the value in a column named “redacted”.

Adopting this approach, the view_database function might look like this:

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