How to get the width of the Tkinter widget?

PHOTO EMBED

Tue Dec 28 2021 14:46:08 GMT+0000 (Coordinated Universal Time)

Saved by @kartick_sriram #python

#Import the required libraries
from tkinter import *

#Create an instance of Tkinter Frame
win = Tk()

#Set the geometry
win.geometry("700x350")

#Set the default color of the window
win.config(bg='#aad5df')

#Create a Label to display the text
label=Label(win, text= "Hello World!",font= ('Helvetica 18 bold'), background= 'white', foreground='purple1')
label.pack(pady = 50)

win.update()

#Return and print the width of label widget
width = label.winfo_width()
print("The width of the label is:", width, "pixels")

win.mainloop()
content_copyCOPY

overlooked this. lifesaver code to get widht and height of widgets. saves lots of time.

https://www.tutorialspoint.com/how-to-get-the-width-of-the-tkinter-widget