I have a Table i am generating using a List (Baseline_Data).
I can get this to print to the terminal fine using:
for row in Baseline_Data:
# Display List as Table
print('\t'.join(row))
What i cant get to work is for this to display in my Tkinter GUI. I found the best way to achieve this would be to generate a label and configure the text.
I have tried:
Import_Lab.config(text=("\t".join(row)))
Which only displays the last row of my List
Import_Lab.config(text=('\n'.join(row)))
Which does the same but displays it as a column
Import_Lab.config(text=(Baseline_Data))
Which displays the full List but as one long continuous line.
How do i display this List as a Multi-line Label ?
import tkinter as tk
from tkinter import ttk
from tkinter import *
root = Tk()
note = ttk.Notebook(root)
def Import_Button1_Press():
Baseline_Data = [
[' IM |', 'IM.Ser', 'Maj', 'Min', 'IIB.Ser', 'Maj', 'Min', 'ManfDate'],
['---------------------------------------------------------------------------'],
['1 - IM1 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['1 - IM2 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['1 - IM3 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['1 - IM4 |', 'NA', 'NA', 'NA', 'NA', 'NA', 'NA', 'NA'],
['1 - IM5 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['1 - IM6 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['2 - IM1 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['2 - IM2 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['2 - IM3 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['2 - IM4 |', 'NA', 'NA', 'NA', 'NA', 'NA', 'NA', 'NA'],
['2 - IM5 |', "12345", "22", "33", "12345", "55", "66", "123456"],
['2 - IM6 |', "12345", "22", "33", "12345", "55", "66", "123456"]
]
for row in Baseline_Data:
# Display List as Table
print('\t'.join(row))
Tab1 = ttk.Frame(note)
canvas1 = Canvas(Tab1, width=550, height=350)
canvas1.pack()
Tab2 = ttk.Frame(note)
canvas2 = Canvas(Tab2, width=550, height=350)
canvas2.pack()
Import_Button1 = tk.Button(Tab2, text = 'Import XML [Baseline]', width=25, height=2, command=Import_Button1_Press)
Import_Button_Window = canvas2.create_window(25, 40, anchor = 'w', window = Import_Button1)
Import_Lab = Label(Tab2, anchor=W)
Import_Lab_Window = canvas2.create_window(275, 175, anchor = 'center', window = Import_Lab)
note.add(Tab1, text = " Main ")
note.add(Tab2, text = " Baseline Data ")
note.pack()
root.mainloop()
You need to generate the complete string, with all the lines (rows of the table) and then pass it to the
textargument, for example:For the table to display correctly, use a monospace font for that label.