0

I would like to display a dataframe as HTML table in tkinter window. I have seen options where I put the dataframe in treeview or use pandastable. However, what I am looking for is to display the table in the tkinter window exactly like it is displayed when I call the table() function. It is more of a visualization thing. Tree view is not good for visualization and pandastable is too complex for my purpose. Is there a way to display the dataframe in the tkinter window exactly like it is displayed in the terminal when I run the code outside of the tkinter window?? I would appreciate the help.

from tkinter import *
import pandas as pd
import numpy as np
from IPython.display import display, clear_output, HTML
def table():
   df = pd.DataFrame(np.random.randint(0,100,size=(10, 4)), columns=list('ABCD'))
   display(HTML(df.to_html()))

root = Tk()
termf = Frame(root, height=400, width=500)


termf.pack(fill=BOTH, expand=YES)    

root.mainloop()
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
Mohammed
  • 23
  • 3
  • tkinter itself has no ability to render html. You'll need to use a third party library. – Bryan Oakley Apr 08 '23 at 18:24
  • Thank you so much for your answer! any suggestion of the third party libraries? – Mohammed Apr 08 '23 at 18:33
  • Does this answer your question? [python tkinter with a simple web wrapper](https://stackoverflow.com/questions/14706069/python-tkinter-with-a-simple-web-wrapper) – relent95 Apr 11 '23 at 01:21
  • I am trying to embed a local HTML file not a website. From what I can see that this is from websites – Mohammed Apr 12 '23 at 03:22
  • Why not create a local file ```temp.html``` and navigate to ```file:///temp.html```? Also most webview libraries support to execute a javascript and you can set the HTML content using the ```document.write()```. – relent95 Apr 13 '23 at 14:41

0 Answers0