Python Forum
[Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view
#1
Hi all,

I'm using Windows 10 and Anaconda Jupyter. I'm trying to build a GUI with one button that randomly picks up a question from an Excel file each time I click on the button. It works fine. But when the question is too long, it just cuts off as in the attached screenshot. I want the line to break, so I can read the whole question and answer it. I tried the wraplength parameter, but it doesn't give me the expected output.

Here is the code:
import tkinter as tk
from tkinter import *
from tkinter import WORD
import pandas as pd
import random

from textwrap import wrap

window = Tk()

window.title("Welcome to your Q App")

window.geometry('900x500')

window.config(bg="#F39C12")
window.resizable(width=False,height=False)




lbl = Label(window, text="Q")

lbl.grid(column=0, row=0)


df = pd.read_excel (r'C:\Users\malmu\Desktop\GUI App\HR_Fragen.xlsx')

def random():
    global l2
    
    df1 = df.sample()  
    
    question = df.sample()
   
    l2.config(text = question)


btn = Button(window, text="Pick up a question", bg="blue", fg="black", command= random)

btn.grid(column=1, row=0)

l1 = tk.Label(text="Please answer",font=("Arial",15),bg="Black",fg="White")

l2 = tk.Label(window, bg="#F73C12",font=("Arial",10),text= "", width=100, justify=LEFT, wraplength=300)

#l2.bind('<Configure>', lambda e: label.config(wraplength=label.winfo_width()))

l2.grid(column=1, row=5)
l1.grid(column=1, row=4)



window.mainloop()
Here how it looks like in the GUI
   


I'm new to the forum, so if my question is not clear or it is not formatted in the way you expect, please let me know.
Many thanks in advance!
Reply


Messages In This Thread
The Text in the Label widget Tkinter cuts off the Long text in the view - by malmustafa - Jun-25-2022, 02:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Button to +1 in text box everytime it's clicked martyloo 1 331 May-01-2024, 02:32 PM
Last Post: Axel_Erfurt
  Tkinter: An image and label are not appearing. emont 7 857 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  Transparent window background, but not text on it muzicman0 7 3,027 Feb-02-2024, 01:28 AM
Last Post: Joically
  TKinter Widget Attribute and Method Quick Reference zunebuggy 3 931 Oct-15-2023, 05:49 PM
Last Post: zunebuggy
  tkinter destroy label inside labelFrame Nick_tkinter 3 4,634 Sep-17-2023, 03:38 PM
Last Post: munirashraf9821
  [Kivy] Create a function to store text fields and drop downs selection in KivyMD floxia 0 1,712 Dec-18-2022, 04:34 AM
Last Post: floxia
  [Tkinter] Updating tkinter text BliepMonster 5 6,314 Nov-28-2022, 01:42 AM
Last Post: deanhystad
  Can't change the colour of Tk button text Pilover 6 15,016 Nov-15-2022, 10:11 PM
Last Post: woooee
  [PyQt] QLineEdit Caret (Text Cursor) Transparency malonn 5 2,926 Nov-04-2022, 09:04 PM
Last Post: malonn
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 1,595 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft

Forum Jump:

User Panel Messages

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