I am trying to display a pandas dataframe in a tkinter label in a popup window so that the user can easily see the data.
Here is the code:
from tkinter import Toplevel, Button, Tkimport tkinter as tkimport pandas as pdpd.set_option('display.max_columns', None)pd.set_option('display.max_rows', None)pd.set_option('display.max_colwidth', 50)pd.set_option('display.width',200)root = Tk()root.geometry("550x600+500+200")df = pd.DataFrame.from_dict({'title': {0: 'Sober', 1: 'Sober (8-Bit Tool Emulation) - 8-Bit Tool Emulation', 2: 'Sober (1993) [8-Bit Tool Emulation]', 3: 'Tool No. 2 (Sober)', 4: 'Sober (Made Famous by Tool)'}, 'artist': {0: 'Tool', 1: '8-Bit Arcade', 2: '8-Bit Arcade', 3: 'UltraRock', 4: 'Baby Lullaby Ensemble'}, 'endPos': {0: 38235, 1: 46546, 2: 56462, 3: 65970, 4: 74870}, 'match': {0: 100, 1: 29, 2: 37, 3: 57, 4: 35}, 'url': {0: 'https://www.musixmatch.com/lyrics/Tool-4/sober?utm_source=application&utm_campaign=api&utm_medium=musixmatch-community%3A1409608317702', 1: 'https://www.musixmatch.com/lyrics/8-Bit-Arcade/Sober-8-Bit-Tool-Emulation-8-Bit-Tool-Emulation?utm_source=application&utm_campaign=api&utm_medium=musixmatch-community%3A1409608317702', 2: 'https://www.musixmatch.com/lyrics/8-Bit-Arcade/Sober-1993-8-Bit-Tool-Emulation?utm_source=application&utm_campaign=api&utm_medium=musixmatch-community%3A1409608317702', 3: 'https://www.musixmatch.com/lyrics/UltraRock/Tool-No-2-Sober?utm_source=application&utm_campaign=api&utm_medium=musixmatch-community%3A1409608317702', 4: 'https://www.musixmatch.com/lyrics/Baby-Lullaby-Ensemble/Sober-Made-Famous-by-Tool?utm_source=application&utm_campaign=api&utm_medium=musixmatch-community%3A1409608317702'}})def new_window() : win = Toplevel() win.geometry("%dx%d+%d+%d" % (1050, 270, root.winfo_x() , root.winfo_y() + 600/4)) tk.Label(win, text= df).grid(row=0, sticky=(tk.E))Button(root, text = "open", command = new_window).pack()root.mainloop()
but this is what the output looks like:
How do I make the values and headers left align? Or is there another way to display this nicer? I am not interested in using actual tables that look like excel, just want to make this more readable.