enter c我要做的是根据列类型中的值更改行颜色。W=黄,E=红和I=蓝。我是刚接触传染病的人。任何想法
代码在这里
我想修改的表

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)发布于 2022-09-02 18:10:35
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()发布于 2022-09-01 22:18:38
furas给出了这样的答案:here,您需要如下所示:
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()https://stackoverflow.com/questions/73537265
复制相似问题