O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling widget resize with <Configure>

There might be occasions when you <indexentry content="window responsiveness:widget resize, handling with ">want to do some specific action when a user resizes a window or a widget. Tkinter provides an event named <Configure>, which can be bound to a callback to react to changes in widget size.

Here is a simple example (see handle_widget_resize.py):

from tkinter import Tk, Label, Packroot= Tk()label = Label(root, text = 'I am a Frame', bg='red')label.pack(fill='both', expand=True)def on_label_resized(event):  print('New Width', label.winfo_width())  print('New Height', label.winfo_height())label.bind("<Configure>", on_label_resized)root.mainloop()

The description of the code is as follows:

  • We have a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required