Jun-25-2022, 02:46 PM
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:
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!
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!