I am new to Tkinter. I have tried a few widgets provided by Tkinter but cannot find a suitable way to display a dataframe.
I tried Tkinter.Text
. I used update()
instead of mainloop()
because I would like to update df
and display again. mainloop()
will block my program. The problem with this approach is that when the df
gets big in size, it cannot be displayed fully.
import pandas
import numpy as np
import Tkinter
root = Tkinter.Tk()
t1 = Tkinter.Text(root)
t1.pack()
df = pandas.DataFrame(np.random.randn(900,2),columns=list('AB'))
t1.insert('end', df)
root.update()
I also tried Tkinter.Lablel
. It actually insert entries of the df
one by one, which is very slow.
from Tkinter import *
for i in range(900):
for j in range(4):
l = Label(text='%d.%d' % (i, j), relief=RIDGE)
l.grid(row=i, column=j, sticky=NSEW)
mainloop()
So what is the easiest way to display a data frame(no need for editing)? To be specific, it should more or less look like an excel spread sheet with scrollbars, and allow the displayed df
to be updated and display again. Also, it should not take too long if df
has hundreds of rows.
Thank you.