Python Forum

Full Version: Label, align imported text from pandas
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

this is my first Python code ever and I'm stuck with imported text alignment. The idea is to load material list from excel sheet into "label". Text has to be clearly visible. I'm using Python 3.8.

"print" command gives aligned table and it looks good:
Output:
Column1 Column2 Column3 0 Material blue 2.50 1 1 Material red 1.05 1 2 Profile No.5 0.75 3 3 Material green 11.40 1 4 Profile No.1 2.50 1
But table loaded into "label" looks terrible:
─░mage


Does anyone have any suggestions how to solve this problem.

My code:
import tkinter as tk
import pandas as pd

HEIGHT = 500
WIDTH = 600


def final_data(df):
    return df

def onReturn(event=None):
    entry.delete(0, 'end')

def sheet_no(entry):
    df = pd.read_excel(open('C:\\Users\\gamybvadas\\Desktop\\Python_apps\\uno.xlsx', 'rb'), sheet_name=entry)
    print(df)
    label['text'] = final_data(df)
     
final_info = lambda: sheet_no(entry.get())

root = tk.Tk()
root.title("test")

root.bind('<Return>', lambda event: sheet_no(entry.get()))

canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

frame = tk.Frame(root, bg='black', bd=1)
frame.place(relx=0.5, rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')

entry = tk.Entry(frame, font="Calibri 25")
entry.place(relwidth=0.8, relheight=1)

button = tk.Button(frame, text="Load", font=40)
button.place(relx=0.8, relheight=1, relwidth=0.2)
button.config(command= final_info)


lower_frame = tk.Frame(root, bg='black', bd=1)
lower_frame.place(relx=0.5, rely=0.25, relwidth=0.75, relheight=0.6, anchor='n')

label = tk.Label(lower_frame, font="Calibri 15", anchor='nw', justify='left')
label.place(relwidth=1, relheight=1)


root.mainloop()
the Text widget-here
instead of a label
So simple.. Blush
Thank You very much joe_momma!