Aug-05-2019, 12:16 PM
Hi guys. I am finance professional who uses python in backend. Now I need to display my analysis in Tkinetr and I faced with the following problem.
In backend I display my pd.Dataframe and apply style.applymap() to change color for specific values ( neg num to red, pos to green). However when I try to display in tkinter the data frame colours do not change. Below is my code. Could you please have a look and say what is wrong and what I am missing?
Your time and help is very much appreciated.
In backend I display my pd.Dataframe and apply style.applymap() to change color for specific values ( neg num to red, pos to green). However when I try to display in tkinter the data frame colours do not change. Below is my code. Could you please have a look and say what is wrong and what I am missing?
Your time and help is very much appreciated.
from tkinter import * from tkinter import ttk from pandas_datareader._utils import RemoteDataError import numpy as np import pandas as pd from scipy.stats import norm import requests from pandas_datareader import data as wb class Scr(): def __init__(self, window1): self.style = ttk.Style() window1.configure(background = 'white') window1.geometry('300x300+120+60') tickers = ['MMM'] mydata = pd.DataFrame() for t in tickers : mydata[t] = wb.DataReader(t, data_source ='yahoo', start = '2014-1-1')['Adj Close'] b=mydata.tail() def color_negative_red(val): if val >175.00: color = 'green' elif val>174.00: color = 'orange' else: color = 'red' return 'color: %s' % color b.style.applymap(color_negative_red) self.frame_content = ttk.Frame(window1) self.frame_content.pack() ttk.Label( self.frame_content, text = b, foreground='',font = ('Arial', 10,'bold')).grid(row = 0, column = 0, padx = 5, sticky = 'sw') def main(): root = Tk() scr = Scr(root) root.mainloop() if __name__ == "__main__": main()