0

Is there a way to find out what width a Label would be for a given text and font, without having to add it to the graphical elements currently being displayed.

I need to get the information without any effect on the GUI, however momentary that effect may be. And, in any case, packing appears to work in a top-down fashion, meaning that controls may expand to fill others higher in the hierarchy but I can't get them to adjust those higher to allow for their actual size.

I'm more used to QML where I can just give an off-screen element the text and font details then just read out the bounding box.

Does anyone know how to do something similar in Tkinter?

Jakub
  • 489
  • 3
  • 13
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953

1 Answers1

2

You can create the Label without calling pack() / grid() / place(), then call winfo_reqwidth() and winfo_reqheight() on the label to get its size.

acw1668
  • 40,144
  • 5
  • 22
  • 34