Python Forum
[python][tkinter][pandas]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[python][tkinter][pandas]
#1
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.


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()
Reply


Messages In This Thread
[python][tkinter][pandas] - by NEL - Aug-05-2019, 12:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Is there a way to plot pandas dataframes using Plotly, with Tkinter? jbitsch 0 2,353 May-04-2020, 10:21 PM
Last Post: jbitsch
  TKinter GUI / Pandas Data frame Loop NSearch 0 6,018 Jun-26-2019, 12:37 AM
Last Post: NSearch

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020