0

I'm currently using Tkinter's Treeview to display a table of data in my GUI, and would like to apply conditional formatting in the Treeview widget so that the background colour of a cell depends on that cell's value (e.g. 0 would be red, and 1-6 are green). Very much like Excel's conditional formatting.

My program reads a CSV file and converts it to a Pandas DataFrame, and I use the Treeview widget to display that data. I also have buttons in my GUI that lets the user filter the data depending on which button is clicked.

I haven't been able to find or think of an easy solution. Would anyone know of a possible work-around or an alternative please?

Desired example output

Mason
  • 1
  • You can't change the color of individual cells. See https://stackoverflow.com/q/48358084/7432 – Bryan Oakley Jan 25 '21 at 20:43
  • How much data are you trying to display? Maybe a grid of labels would be a better solution that the treeview. The treeview was designed more for showing a tree of hierarchical data rather than a table. – Bryan Oakley Jan 25 '21 at 20:57
  • About 130-ish rows, 2000 separate pieces of data. Yeah I looked at doing it as labels as well, but it seems like a big hassle for a really simple thing I'm trying to do, and I'm not sure how it will work with my GUI and all that. Still quite new to all this! – Mason Jan 25 '21 at 21:27
  • I think doing them as labels is probably my only solution to be honest. I'll figure something out. I was hoping I was just missing something! – Mason Jan 25 '21 at 21:35
  • FWIW, I agree with @Bryan that a grid of labels would be better — and don't understand why you seem to think that would be a big hassle. It's would be relatively easy to control each cell's attributes, such as its background color, based on the value being put into it. – martineau Jan 25 '21 at 21:53
  • Doing them as labels isn't the only solution. You could also draw your table on a canvas. Or, you could look at getting some third party module that does tables. – Bryan Oakley Jan 25 '21 at 22:23
  • Ah good to know! :) I'll try the labels – Mason Jan 25 '21 at 22:30

0 Answers0