0
enter c

What I want to do is to Change the row colors based on the values in the column TYPE. W =Yellow, E= Red and I= Blue. I am new to pandastable. Any Ideas

Code here

Table I want to modify

1

def ElogsOpen ():
    #function to strip logs and create a csv file
    elogstrip()
    # window off root parameters
    win = Toplevel(root)
    win.title('Elogs')
    win.geometry ( '1920x1080') 
    win.state('zoomed')
    win.resizable=False
    #File path where CSV was stored when generated
    filepath= folderbtn+'\elogs.csv'
    #Code to display Pandastable from CSV
    class TestApp(tk.Frame):
        def __init__(self, parent, filepath):
            super().__init__(parent)
            self.table = Table(self, showtoolbar=True, showstatusbar=True)
            self.table.importCSV(filepath)
            self.table.autoResizeColumns()
            self.table.show()
    app = TestApp(win, filepath)
    app.pack(fill=tk.BOTH, expand=1)
vimuth
  • 5,064
  • 33
  • 79
  • 116
HASS
  • 1
  • 1
  • Does this answer your question? [SET Color of Cell of one column based on value of column cell Example pandastable](https://stackoverflow.com/questions/60077046/set-color-of-cell-of-one-column-based-on-value-of-column-cell-example-pandastabl) – Ayoub Kaanich Sep 12 '22 at 21:54

2 Answers2

0

furas has given the answer here you need something similar to below:

import tkinter as tk
import pandas as pd
from pandastable import Table

df = pd.DataFrame({
    'A': [1,2,3,'hi',5,'hi'],
    'B': [1,2,3,4,5,6],
    'C': [1,2,'ok',4,'ok',6],
})

root = tk.Tk()

table_frame = tk.Frame(root)
table_frame.pack()

pt = Table(table_frame, dataframe=df) # it can't be `root`, it has to be `frame` 
pt.show()




mask_1 = pt.model.df['A'] == 'hi'
pt.setColorByMask('A', mask_1, 'red')
mask_2 = pt.model.df['B'] >= 5
pt.setColorByMask('B', mask_2, 'blue')
mask_3 = pt.model.df['C'] == 'ok'
pt.setColorByMask('c', mask_2, 'green')

root.mainloop()
SW84
  • 25
  • 5
0
def ElogsOpen ():
#function to strip logs and create a csv file
elogstrip()
# window off root parameters
win = Toplevel(root)
win.title('Elogs')
win.state('zoomed')
win.resizable=False
df=elogdffinal
#restes index
df.reset_index(drop=True, inplace=True)
#makes the index a column
df = df.reset_index(level=0)
#names index
df.index.name = 'Index'
#sets frame to win
table_frame = tk.Frame(win)
#Packs and makes the fram the wholwe screen
table_frame.pack(fill=tk.BOTH, expand=1)
#Puts index that has An E in the Column Type to a list
row1=df.index[df['Type'] == "E "].tolist()
#Puts index that has An I in the Column Type to a list
row2=df.index[df['Type'] == "I "].tolist()
#Puts index that has An W in the Column Type to a list
row3=df.index[df['Type'] == "W "].tolist()
#Makes the table
pt = Table(table_frame, dataframe=df) # it can't be `root`, it has to be `frame`
#Sets the rows by the list row1 to red
pt.setRowColors(rows=row1, clr='#EEA2AD', cols='all')
#Sets the rows by the list row1 to Blue
pt.setRowColors(rows=row2, clr='#B0E2FF', cols='all')
#Sets the rows by the list row1 to Yellow
pt.setRowColors(rows=row3, clr='#FFF68F', cols='all')
#Displays Table
pt.show()
HASS
  • 1
  • 1