Python Forum
[Tkinter] Label, align imported text from pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Label, align imported text from pandas
#1
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:
[Image: program.jpg]

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()
Reply
#2
the Text widget-here
instead of a label
Reply
#3
So simple.. Blush
Thank You very much joe_momma!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 4,856 Jun-26-2022, 06:26 PM
Last Post: menator01
  update text variable on label with keypress knoxvilles_joker 3 4,903 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  How to read text in kivy textinput or Label jadel440 1 5,242 Dec-29-2020, 10:47 AM
Last Post: joe_momma
  align frame inside canvas ro_btz 1 1,838 Sep-11-2020, 04:38 PM
Last Post: Larz60+
  [Kivy] Kivy text label won't shows up! AVD_01 1 2,930 Jun-21-2020, 04:01 PM
Last Post: AVD_01
  [Tkinter] Python 3 change label text gw1500se 6 4,689 May-08-2020, 05:47 PM
Last Post: deanhystad
  [Tkinter] how to update label text from list Roshan 8 5,449 Apr-25-2020, 08:04 AM
Last Post: Roshan
  [Tkinter] Align the width of the entrys with the column captions Particledust 0 1,720 Apr-23-2020, 08:32 AM
Last Post: Particledust
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,768 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  Make Label Text background (default color) transparent using tkinter in python barry76 1 23,759 Nov-28-2019, 10:19 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020