brooklynveezy
brooklynveezy

Reputation: 105

I need pandas dataframe printed to Tkinter Window

I have a dataframe that looks like this:

print (results) 

         Device Name  ... Does this need to be replaced?
3     X6-MX1  ...                           True
5     X1-DX1  ...                           True
6     X4-VX1  ...                           True
7     X1-CX1  ...                           True
8     X2-AX1  ...                           True

Instead of having my "results" dataframe printed to console, I need it displayed in another Tkinter window that populates after hitting my "Run Analysis" button (Notice that in order to obtain "results" you must hit the "Run Analysis" button to run the analysis. This is what I have going on so far.....

runAnalysis () :

[LINES AND LINES OF COMPUTATIONS THAT YOU DONT NEED TO WORRY ABOUT]


    result = result[['Device Name','Hardware Platform', 'Customer Selected Speed', 'Current Max Speed', 'Does this need to be replaced?']]
    root2 = Tk() 
    root2.title("RESULTS OF ANALYSIS")
    t1 = Text(root2) 
    t1.pack() 
    print('These are your results:')
    print(result)
browseButton_Excel = tk.Button(text='RUN ANALYSIS', command=runAnalysis, bg='red', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(175, 375, window=browseButton_Excel)

I feel like I am very close to the solution, but I am clearly not well-versed(enough) with how Tkinter and Pandas can interact with each other. I have tried multiple other solutions I've found on Stack Overflow but I'm unable to relate them to this specific problem.

Upvotes: 0

Views: 276

Answers (1)

Henry Yik
Henry Yik

Reputation: 22493

All you need is DataFrame.to_string and insert into your Text widget:

t1.insert("1.0", result.to_string())

Upvotes: 1

Related Questions