I have created an application that gathers information from a csv file and stores some data into Tkinter labels. The labels are inside label frames, and for some reason the right border of the label frame is broken on the lines where the label text is displayed. I'm running the app on a Windows system.
A minimalistic example that recreates the same issue:
from tkinter import *
root = Tk()
testFrame = LabelFrame(root, text='Test Step', width=250, height=100)
testFrame.grid(row=0, column=0, padx=20, pady=20)
testLabel = Label(testFrame, text='Random text', wraplength=245, anchor=W)
testLabel.place(x=5, y=20, width=250)
root.mainloop()
CodePudding user response:
You specifically requested the width of the label to be 250 pixels. The width of the frame is also 250 pixels. When you use place
, widgets can overlap the borders of their parent, so because the label is offset to the left, it will overlap on the right.
If you set the background of the label to a distinctive color you can see this:
...
testLabel = Label(..., bg="pink")
...
If you're learning tkinter, I strongly recommend against using place
. grid
and pack
do a fantastic job of making sure your widgets all fit within each other and within the window.