There was a previous question asked, here, regarding getting the dimensions of a widget, whenever the window's size is changed.
The linked question and answer work perfectly, but I have a follow up question, and sadly because my account is quite new, I'm not allowed to post comments yet!
My question is; what is the effective difference between:
event.width
and
event.widget.winfo_width()
My full code is below.
from tkinter import *
root = Tk()
display = Canvas(root, width=300, height=300, background="bisque")
display.pack(fill="both", expand=True)
display.create_text(10, 15, anchor="w", tags=["events"])
display.create_text(10, 30, anchor="w", tags=["winfos"])
def show_dims(event):
display.itemconfigure("events", text="event.width: {0}, event.height: {1}".format(event.width, event.height))
display.itemconfigure("winfos", text="winfo_width: {0}, winfo_height: {1}".format(event.widget.winfo_width(), event.widget.winfo_height()))
display.bind("<Configure>", show_dims)
root.mainloop()
As far as I can tell, the code works perfectly. As the window size is changed, the "< Configure>" event calls the show_dims function, which updates the displayed text to show the current width and height of the window in pixels.
Are the two ways I've used of getting window dimensions the same? Is one better for some reason?
Thanks,